Skip to Content
Technical Articles
Author's profile photo geff chang

Enable Colored Logging in Console for Windows

Colored logging lets you see different colors for different log levels in your local development console. An ERROR log may be displayed using red text. A WARN log may be displayed using yellow text, while an INFO log may be displayed using green text. This is useful if you are monitoring the logs while using the SAP Commerce application at the same time. You can see the errors quickly.

For MacOS (and possibly other Linux distributions), colored logging can be easily enabled by setting the ansi.colors property to true in local.properties. For Windows, additional steps need to be done. The SAP Help Portal already has a guide for Colored Logging in Console. However, it’s somewhat incomplete. So, in this guide, I’ll fill in the missing parts.

ASSUMPTIONS:

The following software was used for this guide, though other versions may also work:

  • Windows 10 Home 19041.329
  • SAP Commerce 1905.15
  • Jansi 1.18. This is the Java library that colors your console using ANSI escape sequences.

Other assumptions:

  • You already have a working SAP Commerce set-up. i.e. configuration and initialization is already done

STEPS:

  1. Download the Jansi jar file from: http://fusesource.github.io/jansi/download.html
    As of this writing, the latest version is 1.18.
    NOTE: Clicking on the link to the jar file in the site gives you a “501 HTTPS Required” error. This is because of a change in January 2020: The Central Repository is Moving to HTTPS. The Jansi site needs to update its URLs. This HTTPS link should work: https://repo1.maven.org/maven2/org/fusesource/jansi/jansi/1.18/jansi-1.18.jar
  2. Copy the jar file to: hybris\bin\platform\tomcat\lib
  3. In local.properties, add this property:
    ansi.colors=true​
  4. Start Hybris.

CONCLUSION:

After you’ve done all those 4 steps, you should now have a colorful console. Watching the logs for errors will now be easier, especially if you have a 2-monitor setup with the console in one monitor and the web application in the other.

BONUS:

To change the color of the different log severities, configure log4j2.appender.console.layout.pattern in local.properties, and set the colors for the different log levels. Example:

log4j2.appender.console.layout.pattern=%highlight{%-5p [%t] %X{RemoteAddr}%X{Tenant}%X{CronJob}[%c{1}] %m%n}{FATAL=bright red, ERROR=red, WARN=yellow, INFO=green, DEBUG=cyan, TRACE=white}

Choose from the following colors: black, red, green, yellow, blue, magenta, cyan, and white. If you want a brighter color, add “bright”, like “bright green”.

To change the format or pattern of the log, refer to the Log4j PatternLayout guide: https://logging.apache.org/log4j/2.x/manual/layouts.html#PatternLayout

Assigned Tags

      Be the first to leave a comment
      You must be Logged on to comment or reply to a post.