java.util.logging
you have to specify location of logging.properties file using
-Djava.util.logging.config.file=ABSOLUTE_PATH where ABSOLUTE_PATH is a local file system path. If
you want to put it inside of your jar it may be a problem. XLogger helps to overcome this.
- If java.util.logging.config.file is set and it points to local file system file then XLogger will do nothing.
- If it points to the resource file then it will load it and initialize JUL with it.
- If java.util.logging.config.file is not set then it will search for resource /logging.properties and initialize JUL with it.
- Otherwise it will do nothing
Use it in same way as you would use Logger
static final Logger LOGGER = XLogger.getLogger(HelloWorld.class);
LOGGER.log(Level.FINE, "Publishers: {0}", publishers);
This class also enhance Logger with methods accepting varargs instead of Object[]. It means that you don't need to provide source class name in each call. Same for info logging methods.
-
Field Summary
Fields inherited from class Logger
global, GLOBAL_LOGGER_NAME
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Standard entering method requires user in case of multiple params to pass them inside Object[]: entering(..., new Object[]{"a", "b"}) This method allows to pass multiple params directly: entering(..., "a", "b")void
void
void
void
void
Unfortunately originalLogger
method does not convert result to String and requires you to call it explicitly and only then pass String result.void
Injava.util.logging
to logLevel.FINE
messages you need explicitly pass the corresponding logLevel
to log method.void
Log exception (with entire stacktrace) only whenLevel.FINE
mode is activestatic XLogger
ReturnsLogger
with given class name as a logger name.static XLogger
getLogger
(Class<?> clazz, TracingToken token) static XLogger
Returns Logger with given object class name as a logger name.static XLogger
ReturnsLogger
with given logger name.void
Injava.util.logging
to logLevel.INFO
messages you need explicitly pass the corresponding logLevel
to log method.void
Injava.util.logging
to logLevel.INFO
messages you need explicitly pass the corresponding logLevel
to log method.boolean
isLoggable
(Level level) static void
load()
Initializesjava.util.logging
with default settings as described inXLogger
static void
Initializesjava.util.logging
using specified property resource.static void
Initializesjava.util.logging
using specified property resource combined with specified property Map (properties fromMap
takes priority)void
static void
reset()
ResetLogManager
to default configurationvoid
Injava.util.logging
to logLevel.SEVERE
messages you need explicitly pass the corresponding logLevel
to log method.void
Injava.util.logging
to logLevel.SEVERE
messages you need explicitly pass the corresponding logLevel
to log method.void
Injava.util.logging
to logLevel.SEVERE
messages you need explicitly pass the corresponding logLevel
to log method.void
Injava.util.logging
to logLevel.WARNING
messages you need explicitly pass the corresponding logLevel
to log method.Methods inherited from class Logger
addHandler, config, config, entering, entering, entering, exiting, exiting, fine, fine, finer, finer, finest, finest, getAnonymousLogger, getAnonymousLogger, getFilter, getGlobal, getHandlers, getLevel, getLogger, getName, getParent, getResourceBundle, getResourceBundleName, getUseParentHandlers, info, log, log, log, log, log, log, logp, logp, logp, logp, logp, logp, logrb, logrb, logrb, logrb, logrb, logrb, logrb, logrb, removeHandler, setFilter, setLevel, setParent, setResourceBundle, setUseParentHandlers, severe, severe, throwing, warning, warning
-
Constructor Details
-
XLogger
-
XLogger
-
-
Method Details
-
getLogger
ReturnsLogger
with given class name as a logger name. -
getLogger
ReturnsLogger
with given logger name. -
getLogger
Returns Logger with given object class name as a logger name. It also stores object hashCode as unique ID and includes it as part of the logging source class name -
getLogger
-
load
Initializesjava.util.logging
using specified property resource.- Parameters:
propertyResource
- absolute path to resource file
-
load
Initializesjava.util.logging
using specified property resource combined with specified property Map (properties fromMap
takes priority)Example: set
FileHandler
output file at a runtime:XLogger.load("logging.properties", Map.of("java.util.logging.FileHandler.pattern", "/new/path/log.txt"));
- Parameters:
propertyResource
- absolute path to resource file
-
load
public static void load()Initializesjava.util.logging
with default settings as described inXLogger
Allows
XLogger
explicitly to reset anyjava.util.logging
configuration changes. -
reset
public static void reset()ResetLogManager
to default configuration -
isLoggable
- Overrides:
isLoggable
in classLogger
-
log
-
entering
-
entering
-
enter
Standard entering method requires user in case of multiple params to pass them inside Object[]: entering(..., new Object[]{"a", "b"}) This method allows to pass multiple params directly: entering(..., "a", "b")Unfortunately we cannot overload existing entering methods (
Logger.entering(String, String)
,Logger.entering(String, String, Object)
) because their 2nd argument is a sourceMethod. This will cause an issue that calling:entering("method1", "value")
Will result in calling
Logger.entering(String, String)
and mixup of the arguments (className will be "method1" and sourceMethod will be "value")With a new separate method such problem does not exist:
enter("method1", "value")
With result in sourceMethod be "method1" and params be "value".
-
exit
-
exiting
-
exiting
Unfortunately originalLogger
method does not convert result to String and requires you to call it explicitly and only then pass String result. This method does it for you and converts the result to String and pass it further to Logger. -
info
Injava.util.logging
to logLevel.INFO
messages you need explicitly pass the corresponding logLevel
to log method. This method does it automatically. -
info
Injava.util.logging
to logLevel.INFO
messages you need explicitly pass the corresponding logLevel
to log method. This method does it automatically. -
warning
Injava.util.logging
to logLevel.WARNING
messages you need explicitly pass the corresponding logLevel
to log method. This method does it automatically. -
severe
Injava.util.logging
to logLevel.SEVERE
messages you need explicitly pass the corresponding logLevel
to log method. This method does it automatically. -
severe
Injava.util.logging
to logLevel.SEVERE
messages you need explicitly pass the corresponding logLevel
to log method. This method does it automatically. -
severe
Injava.util.logging
to logLevel.SEVERE
messages you need explicitly pass the corresponding logLevel
to log method. This method does it automatically. -
fine
Injava.util.logging
to logLevel.FINE
messages you need explicitly pass the corresponding logLevel
to log method. This method does it automatically. -
fine
Log exception (with entire stacktrace) only whenLevel.FINE
mode is active
-