Separate only the DEBUG logs to a different log file: WSO2 products.

Nadee Poornima
2 min readJun 22, 2023

--

Hi Everyone,

Ref: https://www.idiva.com/travel-living/home-decor/bring-back-high-life-with-shah-rukh-khan/photogallery/8833

After a long time, I Hope everyone lives happy, healthy and safe. This time I will explain how to generate a separate log file which contains only debug logs with log4j2.

Ref: https://makeameme.org/meme/lets-get-started-rh01o6

Prerequisites

  1. Download APIM 4.2.0 from here. (You can use the WSO2 MI/IS products too)
  2. Install the APIM 4.2.0 on your machine.
  3. Start the APIM 4.2.0 server.

Let’s configure the “log4j2.properties” file to generate a separate file for DEBUG logs only.

Steps

  • Open the “log4j2.properties” file through a text editor, which resides in the “<APIM_420_HOME>/repository/conf” directory.
  • Put the below configuration section under the “Appender” config section.

appender.CARBON_DEBUG_LOGFILE.type = RollingFile
appender.CARBON_DEBUG_LOGFILE.name = CARBON_DEBUG_LOGFILE
appender.CARBON_DEBUG_LOGFILE.fileName = ${sys:carbon.home}/repository/logs/debug-logs/wso2carbon-debug.log
appender.CARBON_DEBUG_LOGFILE.filePattern = ${sys:carbon.home}/repository/logs/debug-logs/wso2carbon-debug-%d{MM-dd-yyyy}.log
appender.CARBON_DEBUG_LOGFILE.layout.type = PatternLayout
appender.CARBON_DEBUG_LOGFILE.layout.pattern = [%d] %5p {%c} — %m%ex%n
appender.CARBON_DEBUG_LOGFILE.policies.type = Policies
appender.CARBON_DEBUG_LOGFILE.policies.time.type = TimeBasedTriggeringPolicy
appender.CARBON_DEBUG_LOGFILE.policies.time.interval = 1
appender.CARBON_DEBUG_LOGFILE.policies.time.modulate = true
appender.CARBON_DEBUG_LOGFILE.policies.size.type = SizeBasedTriggeringPolicy
appender.CARBON_DEBUG_LOGFILE.policies.size.size=10MB
appender.CARBON_DEBUG_LOGFILE.strategy.type = DefaultRolloverStrategy
appender.CARBON_DEBUG_LOGFILE.strategy.max = 20
appender.CARBON_DEBUG_LOGFILE.filter.threshold.type = LevelRangeFilter

#filter only the debug logs
appender.CARBON_DEBUG_LOGFILE.filter.threshold.minLevel = DEBUG
appender.CARBON_DEBUG_LOGFILE.filter.threshold.maxLevel = DEBUG

  • Then add the “CARBON_DEBUG_LOGFILE” appender name to the list of all appenders.

appenders=CARBON_CONSOLE, CARBON_LOGFILE, …. , CARBON_DEBUG_LOGFILE

  • After that, put the following root logger to print the debug logs on the file.

#root loggers

:

rootLogger.appenderRef.CARBON_DEBUG_LOGFILE.ref = CARBON_DEBUG_LOGFILE

  • Save the file and see the change. (No need to restart the server)
Ref: https://www.shutterstock.com/image-photo/photo-nice-overjoyed-enjoying-girl-having-1477843790

All set. :) Now You can enable debug logs on your server(Example: Enable wire logs) and test this case.

My Generated debug log file with debug logs

So give it a try and let me know if you have any concerns on this through a comment—and claps and share. ❤

Bye-bye… let’s meet from the next content … :-) ❤

Ref: https://www.shutterstock.com/search/animal-bye

--

--

Nadee Poornima
Nadee Poornima

Written by Nadee Poornima

Senior Software Engineer at WSO2

No responses yet