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

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -