Separate only the DEBUG logs to a different log file: WSO2 products.
Hi Everyone,
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.
Prerequisites
- Download APIM 4.2.0 from here. (You can use the WSO2 MI/IS products too)
- Install the APIM 4.2.0 on your machine.
- 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)
All set. :) Now You can enable debug logs on your server(Example: Enable wire logs) and test this case.
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 … :-) ❤