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)
Deprecated.
Use
getLogger(String) , because the class name is sometime too close to implementation details. |
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)
Deprecated.
A logger should be specified explicitely with
recoverableException(Logger, Class, String, Throwable) . |
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)
Deprecated.
A logger should be specified explicitely with
unexpectedException(Logger, Class, String, Throwable) . |
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("the.logger.name");
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.@Deprecated public static Logger getLogger(Class<?> classe)
getLogger(String)
, because the class name is sometime too close to implementation details.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)
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, Throwable error)
Level.WARNING
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.
"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
does not log anything at Level.WARNING
.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 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
does not log anything at Level.WARNING
.recoverableException(Logger, Class, String, Throwable)
,
severeException(Logger, Class, String, Throwable)
@Deprecated public static boolean unexpectedException(Class<?> classe, String method, Throwable error)
unexpectedException(Logger, Class, String, Throwable)
.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)
@Deprecated public static boolean recoverableException(Class<?> classe, String method, Throwable error)
recoverableException(Logger, Class, String, Throwable)
.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 does not 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
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.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–2015 The Apache Software Foundation. All rights reserved.