public final class Logging extends Static
getLogger(String)
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(Logger, 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(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(Logger logger,
Class<?> classe,
String method,
Throwable error)
Invoked when a recoverable error occurred.
|
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 occurred.
|
static boolean |
unexpectedException(Logger logger,
Class<?> classe,
String method,
Throwable error)
Invoked when an unexpected error occurred.
|
@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.
public static final Logger LOGGER = Logging.getLogger("the.logger.name");Factory changes will take effect only if this method is invoked before the initialization of such classes.
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 void log(Class<?> classe, String method, LogRecord record)
classe
package name otherwise;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, Class<?> classe, String method, Throwable error)
Level.WARNING
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 described below.
classe
or method
arguments are null, then the originating class name and method name
are inferred from the given error
using the first stack trace element
for which the class name is inside a package or sub-package of the same name than the logger name.
"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, or null
for inferring a default value from other arguments.classe
- the class where the error occurred, or null
for inferring a default value from other arguments.method
- the method where the error occurred, or null
for inferring a default value from other arguments.error
- the error, or null
if none.true
if the error has been logged, or false
if the given error
was null or if the logger does not log anything at Level.WARNING
.recoverableException(Logger, Class, String, Throwable)
,
severeException(Logger, Class, String, Throwable)
public static boolean recoverableException(Logger logger, Class<?> classe, String method, Throwable error)
unexpectedException(…)
except that it does not log the stack trace and uses a lower logging level.logger
- where to log the error, or null
for inferring a default value from other arguments.classe
- the class where the error occurred, or null
for inferring a default value from other arguments.method
- the method name where the error occurred, or null
for inferring a default value from other arguments.error
- the error, or null
if none.true
if the error has been logged, or false
if the given error
was null or if the logger does not 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, or null
for inferring a default value from other arguments.classe
- the class where the error occurred, or null
for inferring a default value from other arguments.method
- the method name where the error occurred, or null
for inferring a default value from other arguments.error
- the error, or null
if none.true
if the error has been logged, or false
if the given error
was null or if the logger does not log anything at Level.SEVERE
.unexpectedException(Logger, Class, String, Throwable)
,
recoverableException(Logger, Class, String, Throwable)
Copyright © 2010–2017 The Apache Software Foundation. All rights reserved.