Class CmsLog
The OpenCms logging mechanism is based on Apache Commons Logging.
However, log4j is shipped with OpenCms and assumed to be used as default logging mechanism.
Since apparently Commons Logging may cause issues in more complex classloader scenarios,
we may switch the logging interface to log4j UGLI
once the final release is available.
The log4j configuration file shipped with OpenCms is located in WEB-INF/classes/log4j2.xml
.
By default, OpenCms will configure log4j using the first log4j2.xml
available found by
Loader.getResource(String, ClassLoader)
.
The following system properties are available for fine-tunning the logging configuration:
opencms.set.logfile
(default:true
)- Set to
false
to bypass the OpenCms standard logging configuration mechanism, delegating this to the logging framework of chose. Note that in this case,- the Workplace logging visualization tools will not be available, and
- you may need to enable automatic configuration of log4j2 (see Using Log4j 2 in Web Applications. This configuration takes place before OpenCms is correctly initialized, and has been disabled in the standard OpenCms distribution because at that point, it has not yet set default values for the relevant system properties
opencms.logfolder
(default: "WEB-INF/logs/
")- Path to the folder where OpenCms will look for logging files to show in the Workplace GUI.
opencms.logfile
(default: "WEB-INF/logs/opencms.log
")- Absolute path to the OpenCms log file.
opencms.set.logfile=false
, OpenCms will first assing
them default values if needed and then will make these system properties available for the configuration of log4j.
In the log4j2.xml
configuration file, system properties can be referenced using the prefix "sys:
" as
in this example:
fileName="${sys:opencms.logfolder}opencms-search.log"
- Since:
- 6.0.0
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
The name of the opencms.log file.static final String
Path to the "logs" folder relative to the "WEB-INF" directory of the application.static org.apache.commons.logging.Log
Log for initialization messages.static final String
Name of the system property that configures the absolute path to the file where OpenCms will write its log.static final String
Name of the system property that configures the path where OpenCms looks for logs to show in the Workplace App. -
Method Summary
Modifier and TypeMethodDescriptionstatic String
Helper for safely evaluating lambda functions to produce log output and catch exceptions they might throw.static org.apache.commons.logging.Log
Returns the log for the selected object.protected static String
Returns the absolute path to the folder of the main OpenCms log file (in the "real" file system).protected static String
Returns the filename of the log file (in the "real" file system).static boolean
isManageable
(String channel) Checks whether a log channel should be manageable through the GUI.static void
makeChannelNonManageable
(String channel) Adds a log channel that should not be manageable via the GUI.static String[]
Render throwable using Throwable.printStackTrace.
-
Field Details
-
FILE_LOG
The name of the opencms.log file.- See Also:
-
FOLDER_LOGS
Path to the "logs" folder relative to the "WEB-INF" directory of the application. -
PROPERTY_LOGFOLDER
Name of the system property that configures the path where OpenCms looks for logs to show in the Workplace App.- See Also:
-
PROPERTY_LOGFILE
Name of the system property that configures the absolute path to the file where OpenCms will write its log.- See Also:
-
INIT
Log for initialization messages.
-
-
Method Details
-
eval
Helper for safely evaluating lambda functions to produce log output and catch exceptions they might throw.- Parameters:
log
- the logger to use for logging errorsstringProvider
- the string provider (normally just given as a lambda function)- Returns:
- the result of the function (or <ERROR> if an exception was thrown)
-
getLog
Returns the log for the selected object.If the provided object is a String, this String will be used as channel name. Otherwise the objects class name will be used as channel name.
- Parameters:
obj
- the object channel to use- Returns:
- the log for the selected object channel
-
isManageable
Checks whether a log channel should be manageable through the GUI.- Parameters:
channel
- the name of the channel- Returns:
- true if the channel should be manageable through the GUI
-
makeChannelNonManageable
Adds a log channel that should not be manageable via the GUI.- Parameters:
channel
- the channel to add
-
render
Render throwable using Throwable.printStackTrace.This code copy from "org.apache.log4j.DefaultThrowableRenderer.render(Throwable throwable)"
- Parameters:
throwable
- throwable, may not be null.- Returns:
- string representation.
-
getLogFileRfsFolder
Returns the absolute path to the folder of the main OpenCms log file (in the "real" file system).If the method returns
null
, this means that the log file is not managed by OpenCms.- Returns:
- the absolute path to the folder of the main OpenCms log file (in the "real" file system)
-
getLogFileRfsPath
Returns the filename of the log file (in the "real" file system).If the method returns
null
, this means that the log file is not managed by OpenCms.- Returns:
- the filename of the log file (in the "real" file system)
-