Class CmsLog
- java.lang.Object
-
- org.opencms.main.CmsLog
-
public final class CmsLog extends java.lang.Object
Provides the OpenCms logging mechanism.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 firstlog4j2.xml
available found byLoader.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 thelog4j2.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
Fields Modifier and Type Field Description static java.lang.String
FILE_LOG
The name of the opencms.log file.static java.lang.String
FOLDER_LOGS
Path to the "logs" folder relative to the "WEB-INF" directory of the application.static org.apache.commons.logging.Log
INIT
Log for initialization messages.static java.lang.String
PROPERTY_LOGFILE
Name of the system property that configures the absolute path to the file where OpenCms will write its log.static java.lang.String
PROPERTY_LOGFOLDER
Name of the system property that configures the path where OpenCms looks for logs to show in the Workplace App.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.String
eval(org.apache.commons.logging.Log log, java.util.concurrent.Callable<java.lang.String> stringProvider)
Helper for safely evaluating lambda functions to produce log output and catch exceptions they might throw.static org.apache.commons.logging.Log
getLog(java.lang.Object obj)
Returns the log for the selected object.protected static java.lang.String
getLogFileRfsFolder()
Returns the absolute path to the folder of the main OpenCms log file (in the "real" file system).protected static java.lang.String
getLogFileRfsPath()
Returns the filename of the log file (in the "real" file system).static boolean
isManageable(java.lang.String channel)
Checks whether a log channel should be manageable through the GUI.static void
makeChannelNonManageable(java.lang.String channel)
Adds a log channel that should not be manageable via the GUI.static java.lang.String[]
render(java.lang.Throwable throwable)
Render throwable using Throwable.printStackTrace.
-
-
-
Field Detail
-
FILE_LOG
public static final java.lang.String FILE_LOG
The name of the opencms.log file.- See Also:
- Constant Field Values
-
FOLDER_LOGS
public static final java.lang.String FOLDER_LOGS
Path to the "logs" folder relative to the "WEB-INF" directory of the application.
-
PROPERTY_LOGFOLDER
public static final java.lang.String PROPERTY_LOGFOLDER
Name of the system property that configures the path where OpenCms looks for logs to show in the Workplace App.- See Also:
- Constant Field Values
-
PROPERTY_LOGFILE
public static final java.lang.String PROPERTY_LOGFILE
Name of the system property that configures the absolute path to the file where OpenCms will write its log.- See Also:
- Constant Field Values
-
INIT
public static org.apache.commons.logging.Log INIT
Log for initialization messages.
-
-
Method Detail
-
eval
public static java.lang.String eval(org.apache.commons.logging.Log log, java.util.concurrent.Callable<java.lang.String> stringProvider)
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
public static org.apache.commons.logging.Log getLog(java.lang.Object obj)
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
public static boolean isManageable(java.lang.String channel)
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
public static void makeChannelNonManageable(java.lang.String channel)
Adds a log channel that should not be manageable via the GUI.- Parameters:
channel
- the channel to add
-
render
public static java.lang.String[] render(java.lang.Throwable throwable)
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.
-
getLogFileRfsPath
protected static java.lang.String 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)
-
getLogFileRfsFolder
protected static java.lang.String 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)
-
-