Elastic Path Commerce uses two logging frameworks for recording activities during run time. Cortex uses Logback, while the rest of the core platform web applications use Apache log4j. Apache log4j is a configurable logging utility for Java that can output messages to a console and a log file. Cortex uses Logback as it incorporates the SLF4J (Simple Logging Facade for Java) API, provides OSGi logging, and has JMX support. Logback can also output messages to a console and a log file.
Elastic Path has made it easier to configure Logback and Log4j by exposing their configuration properties through the parent pom.xml and the .m2/settings.xml. These exposed properties allow you to increase/decrease the level of data logged and define where the log files write to. For more complex configurations, modify the logback.xml or log4j.properties configuration files as described later in the Logback and Log4j Configuration Files topic.
Overview of Logback and Log4j
As Logback is the intended successor to Log4j and both software were designed by the same developer, Logback and Log4j have similar functionality. This section describes some of the common features that both software share, such as Logging Security Levels, log file names, and how to print log messages.
Log4j and Logback write severity ratings along with log messages. Out of the box, Elastic Path Commerce has five logging severity levels:
|Log Level (Severity)||Description|
|ERROR||Indicates a runtime error.|
|WARN||Indicates a warning message.|
Indicates a runtime event messages. For example, a search index build would be an INFO message.
|DEBUG||Indicates a debug message.|
|TRACE||Indicates in-depth activities and inner system workings.|
Log File Names
Each Web Application logs its data to a separate log file.
|Web Application||Log File Name|
|Application Server||Log Location|
To print a Log4j or Logback message from a Java class:
- Get a Logger instance in your class by calling LoggerFactory.getLogger(class)
- Call the Logger method that corresponds to the message's log level and include a message to print to the log file.
Logger logger = LoggerFactory.getLogger(Example.class); logger.debug("Printing debug message");
Elastic Path has exposed common Logback and Log4j configuration settings through the parent pom.xml and the .m2/settings.xml.These configurations allow you to increase/decrease the data logging levels and define where the log files write to. More complex configurations are performed through the logback.xml and log4j.properties configuration files, which are describe later in this section.
If you start your application server from Eclipse, target/logs writes to your Eclipse home directory.
TODO remove Eclipse?
How to Customize Log File Configurations
You can customize log file configurations through the parent pom.xml or through the .m2/settings.xml. For your local developer environment, you would likely configure your local settings.xml, while for your production environment, you would set your pom.xml, build the web apps, and then deploy the web apps to your production server.
For your local developer environment, you can configure your logging settings by adding the following profile to your .m2/settings.xml and setting it as an active profile:
... <profile> <id>ep-log-settings</id> <properties> <ep.log.to>CONSOLE, FILE</ep.log.to> <ep.log.to.logback><![CDATA[<appender-ref ref="CONSOLE"/commerce-legacy/><appender-ref ref="FILE"/commerce-legacy/>]]></ep.log.to.logback> <ep.log.dir>target/logs</ep.log.dir> <ep.log.level>INFO</ep.log.level> </properties> </profile> ... <activeProfiles> <activeProfile>ep-log-settings</activeProfile>
Production environments will likely not have a .m2/settings.xml file, so you will need to configure the log file settings through the parent pom.xml, build the web apps, and then deploy the web apps to your production server in order for the changes to take effect.
<!-- Logging properties --> <ep.log.to>CONSOLE, FILE</ep.log.to> <!-- log4j --> <ep.log.to.logback><![CDATA[<appender-ref ref="CONSOLE"/commerce-legacy/><appender-ref ref="FILE"/commerce-legacy/>]]></ep.log.to.logback> <!-- logback --> <ep.log.level>INFO</ep.log.level> <!-- ep.log.dir is relative to where appserver is started --> <ep.log.dir>target/logs</ep.log.dir>
Specifies what Log4j prints the log messages to. Possible values are CONSOLE and FILE.
Specifies what Logback prints the log messages to. Possible values are CONSOLE and FILE.
|ep.log.dir||Specifies where the log file is created. This is a relative location dependent on your application server.|
Specifies the logging level. Possible values are DEBUG, INFO, WARN, and ERROR.
You may need to configure additional settings for your Logback and Log4j applications or you may want to set different settings for each web application. You need to perform these configurations in the Logback and Log4j configurations files. The following describes where these files are located and provide links to the application's configuration manuals.
- Core web application's log4j.properties file in <web application root>\src\main\webapp\WEB-INF\misc. For instruction on how to can configure Log4j, refer to the Log4j configuration manual.
- You can find Cortex's logback.xml in relos\logback-config\src\main\filtered-resources. For instruction on how you to configure Logback, refer to the Logback configuration manual. Warning: logback.xml Warning
If you modify logback.xml you need to rebuild both the logback-config and cortex-dce-webapp projects.