public final class Logging extends Object
getLogger(String)
, not Logger.getLogger(String)
. This is necessary in order to give GeoTools a chance to redirect log
events to an other logging framework, for example commons-logging.
Example: In order to redirect every GeoTools log events to Commons-logging, invoke the following once at application startup:
Logging.GEOTOOLS.setLoggerFactory("org.geotools.util.logging.CommonsLoggerFactory");
Modifier and Type | Field and Description |
---|---|
static Logging |
ALL
Logging configuration that apply to all packages.
|
static Logging |
GEOTOOLS
Logging configuration that apply only to GeoTools packages.
|
Modifier and Type | Method and Description |
---|---|
void |
forceMonolineConsoleOutput()
Configures the default console handler in order
to log records on a single line instead of two lines.
|
void |
forceMonolineConsoleOutput(Level level)
Same as
forceMonolineConsoleOutput() , but additionnaly set an optional logging
level. |
static Logger |
getLogger(Class<?> classe)
Returns a logger for the specified class.
|
static Logger |
getLogger(String name)
Returns a logger for the specified name.
|
LoggerFactory<?> |
getLoggerFactory()
Returns the logger factory, or
null if none. |
static Logging |
getLogging(String name)
Returns a
Logging instance for the specified base logger. |
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.
|
void |
setLoggerFactory(LoggerFactory<?> factory)
Sets a new logger factory for this
Logging instance and every children. |
void |
setLoggerFactory(String className)
Sets a new logger factory from a fully qualidifed class name.
|
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.
|
static boolean |
unexpectedException(String paquet,
Class<?> classe,
String method,
Throwable error)
Deprecated.
Use one of the other
unexpectedException methods instead. |
public static final Logging ALL
public static final Logging GEOTOOLS
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 Logger getLogger(String name)
If no factory was found or if the factory choose to not redirect the loggings, then this
method returns the usual Logger.getLogger(name)
.
name
- The logger name.public static Logging getLogging(String name)
Logging
instance for the specified base logger. This instance is used for
controlling logging configuration in GeoTools. For example methods like forceMonolineConsoleOutput()
are invoked on a Logging
instance.
Logging
instances follow the same hierarchy than Logger
, i.e. "org.geotools"
is the parent of "org.geotools.referencing"
, "org.geotools.metadata"
, etc.
name
- The base logger name.public LoggerFactory<?> getLoggerFactory()
null
if none. This method returns the logger set by
the last call to setLoggerFactory(org.geotools.util.logging.LoggerFactory<?>)
on this Logging
instance or on one of its
parent.public void setLoggerFactory(LoggerFactory<?> factory)
Logging
instance and every children. The specified
factory will be used by getLogger(name)
when
name
is this Logging
name or one of its children.public void setLoggerFactory(String className) throws ClassNotFoundException, IllegalArgumentException
setLoggerFactory(LoggerFactory)
when the underlying logging framework is not
garanteed to be on the classpath.className
- The fully qualified factory class name.ClassNotFoundException
- if the specified class was not found.IllegalArgumentException
- if the specified class is not a subclass of LoggerFactory
, or if no public static getInstance()
method has been found or can
be executed.public void forceMonolineConsoleOutput()
ConsoleHandler
using a SimpleFormatter
, this
method replaces the simple formatter by an instance of MonolineFormatter
. If no
ConsoleHandler
are found, then a new one is created.
Note: this method may have no effect if the loggings are redirected to an other
logging framework, for example if #redirectToCommonsLogging
has been invoked.
public void forceMonolineConsoleOutput(Level level)
forceMonolineConsoleOutput()
, but additionnaly set an optional logging
level. If the specified level is non-null, then all Handler
s using
the monoline formatter will be set to the specified level.
Note: Avoid this method as much as possible, since it overrides user's level setting. A user trying to configure his logging properties may find confusing to see his setting ignored.
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.geotools.image"
, then this method
will uses the first stack trace element where the fully qualified class name starts with
"org.geotools.image"
or "org.geotools.image.io"
, but not "org.geotools.imageio"
.logger
- Where to log the error.error
- The error that occured.true
if the error has been logged, or false
if the logger doesn't log
anything at the WARNING
level.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 optionnaly 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:
Automatic inference is not 100% reliable, since the Java Virtual Machine is free to omit stack frame in optimized code.
When an exception occured in a private method used internally by a public method, we sometime want to log the warning for the public method instead, since the user is not expected to know anything about the existence of the private method. If a developper really want to know about the private method, the stack trace is still available anyway.
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 the WARNING
level.public static boolean unexpectedException(String paquet, Class<?> classe, String method, Throwable error)
unexpectedException
methods instead.WARNING
level to the logger for the specified package name. The originating
class name and method name can optionnaly be specified. If any of them is null
, then
it will be inferred from the error stack trace as in unexpectedException(Logger,
Throwable)
.paquet
- The package where the error occurred, or null
. This information is used
for fetching an appropriate Logger
for logging 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 the WARNING
level.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 the WARNING
level.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 the specified level.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 the specified level.Copyright © 1996–2019 Geotools. All rights reserved.