Using
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
-
Method Summary
Modifier and TypeMethodDescriptionvoid
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.static 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.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.Visible for tests only.
- 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
-
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.
-