public final class LogProvider
extends java.lang.Object
getLogger(Class)
method to retrieve a logger
instance.
If the log is also written to a file by defining the method argument of
isStorable
then all logging is persistently stored on the mounted
drive. The drive depends on the OS:
Per default a flag for the MSTApp logger is set to false
and can be specified by
calling one of both methods #getLogger(java.lang.Class, java.util.logging.Level, de.desy.mst.libs.util.helper.LogProvider.ELoggingProperty, boolean)
and
#getLogger(java.lang.Class, java.util.logging.Level, de.desy.mst.libs.util.helper.LogProvider.ELoggingProperty, boolean)
, both by setting
the third parameter to true
.
NOTE 1: The usage of the property LogProvider.ELoggingProperty.FILE_STORAGE
effects from the first class who gets the logger during runtime. All
consecutive loggers will indirectly also write to the created file. Best call
for project logging is therefore in the class which include the main functionality.
NOTE 2: Furthermore the property LogProvider.ELoggingProperty.MCS_LOGGING
only has an effect on that class which gets the logger with this field set.
In other words, this flag is limited to the calling class.
NOTE 2: Never use the method setLogFilename(String)
! The file name is filter from the
concrete package and main class name instance from its first call to getLogger(Class)
.
So you should always create one logger in the main class to clarify
the file name. If you do create a logger at a later stage in some
other class or in a sub-package the file name will change to the concrete
first calling class instance. This can result in unexpected file names. The
log file tries to find the corresponding log directory on windows drive L. If
it doesn't exist it will create one. In this directory the project name for
the class package name is filter to a directory name.
Modifier and Type | Class and Description |
---|---|
static class |
LogProvider.ELoggingProperty |
static class |
LogProvider.MCSHandlerBridge |
Modifier and Type | Field and Description |
---|---|
static boolean |
DEFAULT_TIME_AND_DATE |
static java.lang.String |
LOG_DIRECTORY |
Modifier and Type | Method and Description |
---|---|
static java.util.logging.Logger |
getLogger(java.lang.Class<?> clazz)
Creates the current Java logger instance of the specified class.
|
static java.util.logging.Logger |
getLogger(java.lang.Class<?> clazz,
java.util.logging.Level level)
Gets the current Java logger instance of the specified class and level.
|
static java.util.logging.Logger |
getLogger(java.lang.Class<?> clazz,
java.util.logging.Level level,
boolean hasDateFormat,
LogProvider.ELoggingProperty... logProperties)
Gets the current Java logger instance of the specified class and
a level which is specified with its log level.
|
static java.util.logging.Logger |
getLogger(java.lang.Class<?> clazz,
java.util.logging.Level level,
LogProvider.ELoggingProperty... logProperties)
Gets the current Java logger instance of the specified class and level.
|
static java.util.logging.Logger |
getLogger(java.lang.Class<?> clazz,
LogProvider.ELoggingProperty... logProperties)
Gets the current Java logger instance of the specified class.
|
static void |
setLogFilename(java.lang.String logFilename)
Deprecated.
Never use this method. The file name is filter from the
concrete package and main class name on the first call to
getLogger(Class) .
So you should always create one logger in the main class to clarify
the file name. This function will return immediately without
modifying this class. |
public static final boolean DEFAULT_TIME_AND_DATE
public static final java.lang.String LOG_DIRECTORY
public static java.util.logging.Logger getLogger(java.lang.Class<?> clazz)
getLogger(Class, Level)
.
The default log level is set to Level.INFO
. The logging is stored
in a file.clazz
- Logging class instance.public static java.util.logging.Logger getLogger(java.lang.Class<?> clazz, java.util.logging.Level level)
#getLogger(java.lang.Class, java.util.logging.Level, de.desy.mst.libs.util.helper.LogProvider.ELoggingProperty, boolean)
.
The default log level is set to Level.INFO
. The logging is stored
in a file and only a timestamp is printed.clazz
- Logging class instance.level
- Log level.public static java.util.logging.Logger getLogger(java.lang.Class<?> clazz, java.util.logging.Level level, LogProvider.ELoggingProperty... logProperties)
#getLogger(java.lang.Class, java.util.logging.Level, de.desy.mst.libs.util.helper.LogProvider.ELoggingProperty, boolean)
.
The default log level is set to Level.INFO
. The logging is stored
in a file and only a timestamp is printed.
NOTE 1: The usage of the property LogProvider.ELoggingProperty.FILE_STORAGE
effects from the first class who gets the logger during runtime. All
consecutive loggers will indirectly also write to the created file. Best call
for project logging is therefore in the class which include the main functionality.
NOTE 2: Furthermore the property LogProvider.ELoggingProperty.MCS_LOGGING
only has an effect on that class which gets the logger with this field set.
In other words, this flag is limited to the calling class.
clazz
- Logging class instance.level
- Log level.logProperties
- Specifies the logging properties used for the returned instance.public static java.util.logging.Logger getLogger(java.lang.Class<?> clazz, LogProvider.ELoggingProperty... logProperties)
setLogFilename(String)
. For more information you should
have a look at #getLogger(java.lang.Class, java.util.logging.Level, de.desy.mst.libs.util.helper.LogProvider.ELoggingProperty, boolean)
.
The default log level is set to Level.INFO
and only a timestamp
is printed.
NOTE 1: The usage of the property LogProvider.ELoggingProperty.FILE_STORAGE
effects from the first class who gets the logger during runtime. All
consecutive loggers will indirectly also write to the created file. Best call
for project logging is therefore in the class which include the main functionality.
NOTE 2: Furthermore the property LogProvider.ELoggingProperty.MCS_LOGGING
only has an effect on that class which gets the logger with this field set.
In other words, this flag is limited to the calling class.
clazz
- Logging class instance.logProperties
- Specifies the logging properties used for the returned instance.public static java.util.logging.Logger getLogger(java.lang.Class<?> clazz, java.util.logging.Level level, boolean hasDateFormat, LogProvider.ELoggingProperty... logProperties)
public class A { private static final Logger log = LogProvider.getLogger(A.class); ... void abc() { log.info("only a comment..."); } }You can influence the behavior of the logger with a property file. This file must contain valid key-value-pairs for controlling the behavior of the logger. For more information about the file see at Wikibooks (DE) web page. One example property file is included in the root folder
examples
under log/mpsdiag.properties
.
This can easily be set via the command line argument of
-Djava.util.logging.config.file=
/path/to/app.properties.
NOTE 1: The usage of the property LogProvider.ELoggingProperty.FILE_STORAGE
effects from the first class who gets the logger during runtime. All
consecutive loggers will indirectly also write to the created file. Best call
for project logging is therefore in the class which include the main functionality.
NOTE 2: Furthermore the property LogProvider.ELoggingProperty.MCS_LOGGING
only has an effect on that class which gets the logger with this field set.
In other words, this flag is limited to the calling class.
Moreover you can also specify the log filename with the method setLogFilename(String)
.
clazz
- Logging class instance.level
- Log level.hasDateFormat
- Specifies if the logging message only includes the
time (false) or time with date (true).logProperties
- Specifies the logging properties used for the returned instance.@Deprecated public static final void setLogFilename(java.lang.String logFilename)
getLogger(Class)
.
So you should always create one logger in the main class to clarify
the file name. This function will return immediately without
modifying this class.%g
.logFilename
- Log file name. If the file name is set to null or empty
it will return immediately.17-November-2016 09:39 Deutsches Elektronen-Synchrotron DESY in der Helmholtz-Gemeinschaft