User Tools

Site Tools


log4j

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
log4j [2015/10/15 12:47] – [Property Substitution] skiplog4j [2020/12/27 20:35] (current) – external edit 127.0.0.1
Line 1: Line 1:
 +==== Adding Configurations ====
 +Rules:
 +  - The configuration has to be stored in classpath. (In eclipse RCP you can store it in a Fragment)
 +  - The path is set relatively to the classpath folders
 +  - The path can be passed sa a JVM attribute:
  
 +<code>
 +-Dlog4j.configuration=/log4j_config/alf.log4j.properties -Dlog4j.debug
 +</code>
 +
 +
 +Example properties File:
 +
 +<code>
 +# Set root logger level to DEBUG and its only appender to Console.
 +log4j.rootCategory=INFO, others
 +log4j.category.de.ivu=DEBUG, IVUfile, IVUconsole
 +log4j.additivity.de.ivu=false
 +log4j.category.de.ivu.fare.rcp.gui.accordion=ERROR
 +
 +##################
 +# general appender
 +##################
 +# console
 +log4j.appender.others=org.apache.log4j.ConsoleAppender
 +log4j.appender.others.layout=org.apache.log4j.PatternLayout
 +log4j.appender.others.layout.ConversionPattern=*GENERAL* %d <%t> [%p] %c - %m%n
 +log4j.appender.others.Threshold=WARN
 +
 +##################
 +# ivu appender
 +##################
 +# console
 +log4j.appender.IVUconsole=org.apache.log4j.ConsoleAppender
 +log4j.appender.IVUconsole.layout=org.apache.log4j.PatternLayout
 +log4j.appender.IVUconsole.layout.ConversionPattern=*OVU-LOG* %d <%t> [%p] %c - %m%n
 +log4j.appender.IVUconsole.Threshold=DEBUG
 +
 +# file
 +log4j.appender.IVUfile=org.apache.log4j.RollingFileAppender
 +log4j.appender.IVUfile.File=./log/application.log
 +log4j.appender.IVUfile.MaxFileSize=2048KB
 +log4j.appender.IVUfile.MaxBackupIndex=3
 +log4j.appender.IVUfile.layout=org.apache.log4j.PatternLayout
 +log4j.appender.IVUfile.layout.ConversionPattern=*OVU-LOG* %d <%t> [%p] %c - %m%n
 +log4j.appender.IVUfile.Threshold=DEBUG
 +
 +
 +</code>
 +
 +
 +==== Property Substitution ====
 +It is possible to use system properties / environment variables etc. inside the log4j configuration.
 +The syntax looks as following:
 +<code>
 +${env:APPDATA}
 +${sys:osgi.nl.user}
 +...
 +</code>
 +
 +All the details about the sysntax and all possible substitution sources are listed here: \\ https://logging.apache.org/log4j/2.0/manual/configuration.html#PropertySubstitution
 +
 +
 +==== FILTER ====
 +
 +Filter may be used to filter out some stuff.
 +
 +E.g. the RegEx Filter is very powerfull and may be placed directly inside the configuraiton, to filter everything:
 +
 +<code>
 +<configuration status="warn" packages="org.graylog2.log4j2">
 + <RegexFilter regex=".*(TECHMODULE).*" onMatch="ACCEPT" onMismatch="DENY"/>
 +</code>