log4j2 - Lo4j config - Log to different files based on type of mesasge prefix -
hello using log4j2 logging , little confused how can log message different file based on message prefix.
for example, messages logged in single logs folder.
set of messages this: 'com.project.latency: projectname=[moopointproject].......'
some of other log messages of format: 'com.project.latency: projectname=[dataplaneproject].......'
i want log messages contain moopointproject in specific file , 1 containing dataplaneproject in separate log file.
is there specific way can other changing logging level itself?
set several appenders 1 each project name. example:
<rollingfile name="rollingfile" filename="logs/moopointproject.log" filepattern="logs/app-%d{mm-dd-yyyy}.log.gz"> <regexfilter regex=".*moopointproject.*" onmatch="accept" onmismatch="deny"/> <patternlayout> <pattern>%d %p %c{1.} [%t] %m%n</pattern> </patternlayout> <timebasedtriggeringpolicy /> </rollingfile>
and
<rollingfile name="rollingfile" filename="logs/dataplaneproject.log" filepattern="logs/app-%d{mm-dd-yyyy}.log.gz"> <regexfilter regex=".*dataplaneproject.*" onmatch="accept" onmismatch="deny"/> <patternlayout> <pattern>%d %p %c{1.} [%t] %m%n</pattern> </patternlayout> <timebasedtriggeringpolicy /> </rollingfile>
then assign both appenders logger(s). since regexpfilter
accepts project-spcific lines them appropriate files separately.
p.s. - find detail on other types of filters here.
Comments
Post a Comment