Class CmsLog

java.lang.Object
org.opencms.main.CmsLog

public final class CmsLog extends 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 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.
If the logging configuration is not bypassed by setting 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

    Fields
    Modifier and Type
    Field
    Description
    static 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 Type
    Method
    Description
    static String
    eval(org.apache.commons.logging.Log log, Callable<String> stringProvider)
    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
    Checks whether a log channel should be manageable through the GUI.
    static void
    Adds a log channel that should not be manageable via the GUI.
    static String[]
    render(Throwable throwable)
    Render throwable using Throwable.printStackTrace.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • FILE_LOG

      public static final String FILE_LOG
      The name of the opencms.log file.
      See Also:
    • FOLDER_LOGS

      public static final String FOLDER_LOGS
      Path to the "logs" folder relative to the "WEB-INF" directory of the application.
    • PROPERTY_LOGFOLDER

      public static final 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:
    • PROPERTY_LOGFILE

      public static final String PROPERTY_LOGFILE
      Name of the system property that configures the absolute path to the file where OpenCms will write its log.
      See Also:
    • INIT

      public static org.apache.commons.logging.Log INIT
      Log for initialization messages.
  • Method Details

    • eval

      public static String eval(org.apache.commons.logging.Log log, Callable<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 errors
      stringProvider - 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(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(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(String channel)
      Adds a log channel that should not be manageable via the GUI.
      Parameters:
      channel - the channel to add
    • render

      public static String[] render(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.
    • getLogFileRfsFolder

      protected static 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)
    • getLogFileRfsPath

      protected static 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)