public final class Logging extends Static
getLogger(Class)
static method defined in this Logging
class rather than the one defined in the standard Logger
class, in order to give SIS a
chance to redirect the logs to an other framework like
Commons-logging or
Log4J.
This class provides also some convenience static methods, including:
log(Class, String, LogRecord)
for setting
the logger name, source class name and
source method name of the given record
before to log it.unexpectedException(Class, String, Throwable)
for reporting an anomalous but
nevertheless non-fatal exception.Defined in the sis-utility module
Modifier and Type | Method and Description |
---|---|
static Logger |
getLogger(Class<?> classe)
Returns a logger for the specified class.
|
static Logger |
getLogger(String name)
Returns a logger for the specified name.
|
static LoggerFactory<?> |
getLoggerFactory()
Returns the factory used for obtaining
Logger instances, or null if none. |
static void |
log(Class<?> classe,
String method,
LogRecord record)
Logs the given record to the logger associated to the given class.
|
static boolean |
recoverableException(Class<?> classe,
String method,
Throwable error)
Invoked when a recoverable error occurs.
|
static boolean |
recoverableException(Logger logger,
Class<?> classe,
String method,
Throwable error)
Invoked when a recoverable error occurs.
|
static void |
setLoggerFactory(LoggerFactory<?> factory)
Sets a new factory to use for obtaining
Logger instances. |
static boolean |
severeException(Logger logger,
Class<?> classe,
String method,
Throwable error)
Invoked when a severe error occurs.
|
static boolean |
unexpectedException(Class<?> classe,
String method,
Throwable error)
Invoked when an unexpected error occurs.
|
static boolean |
unexpectedException(Logger logger,
Class<?> classe,
String method,
Throwable error)
Invoked when an unexpected error occurs.
|
static boolean |
unexpectedException(Logger logger,
Throwable error)
Invoked when an unexpected error occurs.
|
@Configuration public static void setLoggerFactory(LoggerFactory<?> factory)
Logger
instances.
If the given factory
argument is null
(the default),
then the standard Logging framework will be used.
Factory changes will take effect only if this method is invoked before the initialization of such classes.public static final Logger LOGGER = Logging.getLogger(TheClass.class);
factory
- The new logger factory, or null
if none.public static LoggerFactory<?> getLoggerFactory()
Logger
instances, or null
if none.null
if none.public static Logger getLogger(String name)
Logger.getLogger(name)
.name
- The logger name.public static Logger getLogger(Class<?> classe)
getLogger(String)
with the package name as the logger name.classe
- The class for which to obtain a logger.public static void log(Class<?> classe, String method, LogRecord record)
getLogger(Class)
;classe
- The class for which to obtain a logger.method
- The name of the method which is logging a record.record
- The record to log.public static boolean unexpectedException(Logger logger, Throwable error)
WARNING
level to the specified logger. The originating
class name and method name are inferred from the error stack trace, using the
first stack trace element for which the class
name is inside a package or sub-package of the logger name. For example if
the logger name is "org.apache.sis.image"
, then this method will uses
the first stack trace element where the fully qualified class name starts with
"org.apache.sis.image"
or "org.apache.sis.image.io"
, but not
"org.apache.sis.imageio"
.logger
- Where to log the error.error
- The error that occurred.true
if the error has been logged, or false
if the logger
doesn't log anything at Level.WARNING
.public static boolean unexpectedException(Logger logger, Class<?> classe, String method, Throwable error)
WARNING
level to the specified logger. The originating
class name and method name can optionally be specified. If any of them is
null
, then it will be inferred from the error stack trace as in
unexpectedException(Logger, Throwable)
.
Explicit value for class and method names are sometime preferred to automatic inference for the following reasons:
logger
- Where to log the error.classe
- The class where the error occurred, or null
.method
- The method where the error occurred, or null
.error
- The error.true
if the error has been logged, or false
if the logger
doesn't log anything at Level.WARNING
.recoverableException(Logger, Class, String, Throwable)
,
severeException(Logger, Class, String, Throwable)
public static boolean unexpectedException(Class<?> classe, String method, Throwable error)
WARNING
level to a logger inferred from the given class.classe
- The class where the error occurred.method
- The method where the error occurred, or null
.error
- The error.true
if the error has been logged, or false
if the logger
doesn't log anything at Level.WARNING
.recoverableException(Class, String, Throwable)
public static boolean recoverableException(Class<?> classe, String method, Throwable error)
unexpectedException
except that it doesn't log the stack trace and uses a lower logging level.classe
- The class where the error occurred.method
- The method name where the error occurred.error
- The error.true
if the error has been logged, or false
if the logger
doesn't log anything at Level.FINE
.unexpectedException(Class, String, Throwable)
public static boolean recoverableException(Logger logger, Class<?> classe, String method, Throwable error)
unexpectedException
except that it doesn't log the stack trace and uses a lower logging level.logger
- Where to log the error.classe
- The class where the error occurred.method
- The method name where the error occurred.error
- The error.true
if the error has been logged, or false
if the logger
doesn't log anything at Level.FINE
.unexpectedException(Logger, Class, String, Throwable)
,
severeException(Logger, Class, String, Throwable)
public static boolean severeException(Logger logger, Class<?> classe, String method, Throwable error)
unexpectedException
except that it logs the message at the SEVERE
level.logger
- Where to log the error.classe
- The class where the error occurred.method
- The method name where the error occurred.error
- The error.true
if the error has been logged, or false
if the logger
doesn't log anything at Level.SEVERE
.unexpectedException(Logger, Class, String, Throwable)
,
recoverableException(Logger, Class, String, Throwable)
Copyright © 2010–2013 The Apache Software Foundation. All rights reserved.