log4j2 - Why isn't my Log4J code working with the FlumeAppender? -
i'm getting following error log4j :
2015-07-07 18:24:00,974 error error processing element flume: class_not_found 2015-07-07 18:24:01,009 error appender auditlogger cannot located. route igno red
the following log4j2 xml file :
<?xml version="1.0" encoding="utf-8"?> <configuration status="warn"> <appenders> <console name="console" target="system_out"> <patternlayout pattern="%d{hh:mm:ss.sss} [%t] %-5level %logger{36} - %msg%n"/> </console> <file name="myfile" filename="outputlogfile.log" immediateflush="false" append="false"> <patternlayout pattern="%d{yyy-mm-dd hh:mm:ss.sss} [%t] %-5level %logger{36} - %msg%n"/> </file> <flume name="auditlogger" compress="true"> <agent host="192.168.10.101" port="8800"/> <agent host="192.168.10.102" port="8800"/> <rfc5424layout enterprisenumber="18060" includemdc="true" appname="myapp"/> </flume> <routing name="routing"> <routes pattern="$${sd:type}"> <route> <rollingfile name="rolling-${sd:type}" filename="${sd:type}.log" filepattern="${sd:type}.%i.log.gz"> <patternlayout> <pattern>%d %p %c{1.} [%t] %m%n</pattern> </patternlayout> <sizebasedtriggeringpolicy size="100" /> </rollingfile> </route> <route ref="auditlogger" key="audit"/> </routes> </routing> </appenders> <loggers> <root level="all"> <appender-ref ref="console"/> <appender-ref ref="myfile"/> <!-- added_in --> </root> </loggers> </configuration>
then , tried add in flumeappender this:
import org.apache.logging.log4j.flume;
but didn't work after ... how set-up flumeappender ?
<rollingfile name="messaging_file" filename="log/messaging.log" filepattern="log/mm_messaging.log.%i"> <patternlayout pattern="%m%n/> <policies> <sizebasedtriggeringpolicy size="1mb"/> </policies> <defaultrolloverstrategy max="3"/> <filters> <thresholdfilter level="info" onmatch="accept" onmismatch="deny"/> </filters> </rollingfile>
here example creates new file every time file size becomes 1 mb, can set size standard sizes such 10 kb 345 mb etc.
the %i in file pattern must included doing size based rollovers. max variable determines number of files keep. on time lose oldest logs.
lastly threshold filter logs info messages , below ie. (info,warn,error...) exact match set onmatch neutral , add threshold filter this
<filters> <thresholdfilter level="info" onmatch="neutral" onmismatch="deny"/> <thresholdfilter level="eror" onmatch="deny" onmismatch="accept"/> </filters>
they processed in order. neutral means move on next filter. accept means logged. if message gets passed through filters neutral status default accepted if there no filters.
as far seperating logs output straightforward way choose appenders class path's log defining logger path , adding appender ref log want. simple way use marker , markerfilter. lastly believe there routingappender more efficient more complicated , don't have experience using it.
spend time on developer website log4j2 have relatively api reference. want in new implementation.
Comments
Post a Comment