add log4j
This commit is contained in:
parent
ef2abb6e64
commit
9f76abc405
313
log4j/README.md
Normal file
313
log4j/README.md
Normal file
@ -0,0 +1,313 @@
|
||||
---
|
||||
gitea: none
|
||||
include_toc: true
|
||||
---
|
||||
# log4j
|
||||
|
||||
## Tutorial log4j 2
|
||||
|
||||
https://howtodoinjava.com/log4j2/
|
||||
|
||||
``` xml
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!--
|
||||
|
||||
log4j 2 Mini-Tutorial
|
||||
*********************
|
||||
comments by Ru
|
||||
more infos see: https://logging.apache.org/log4j/2.x/
|
||||
example from
|
||||
https://bitbucket.org/docuteam/cosmos/src/master/docuteam-feeder/src/main/resources/log4j2.xml
|
||||
-->
|
||||
|
||||
<Configuration
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://logging.apache.org/log4j/2.0/config"
|
||||
xmlns="http://logging.apache.org/log4j/2.0/config" status="WARN"
|
||||
strict="true">
|
||||
|
||||
<!--
|
||||
Properties are like variables, that will be used in the Appenders section
|
||||
-->
|
||||
<Properties>
|
||||
|
||||
<!--
|
||||
set property "name" to "feeder", which will be used in the appender ROLLINGFILE
|
||||
-->
|
||||
<Property name="name">feeder</Property>
|
||||
|
||||
<!--
|
||||
set property "pattern", which will be used in the appender ROLLINGFILE
|
||||
-->
|
||||
<Property name="pattern">%-5p %d{dd.MM.yyyy HH:mm:ss.SSS} (%c{2}.%M()[%L]) %m%n</Property>
|
||||
</Properties>
|
||||
|
||||
<!--
|
||||
The APPENDER object is responsible for publishing logging information to various preferred destinations such as a database, file, console, UNIX Syslog, etc.
|
||||
-->
|
||||
<Appenders>
|
||||
<!--
|
||||
Output to console
|
||||
- type: must be "Console"
|
||||
- target: decide on which console the outut will be transferred to.
|
||||
The OS has 2 (or 3) consoles. One for output, one for only errors.
|
||||
-->
|
||||
<Appender type="Console" name="STDOUT" target="SYSTEM_OUT">
|
||||
<PatternLayout pattern="${pattern}" charset="UTF-8" />
|
||||
</Appender>
|
||||
|
||||
<Appender type="Console" name="STDERR" target="SYSTEM_ERR">
|
||||
<PatternLayout pattern="${pattern}" charset="UTF-8" />
|
||||
</Appender>
|
||||
|
||||
<!--
|
||||
Output in log file
|
||||
- fileName: Path/filename with the property ${name}
|
||||
- filePattern: Path/filename for the archived log files (when rollover occurs)
|
||||
-->
|
||||
<RollingFile name="ROLLINGFILE"
|
||||
fileName="logs/${name}.log"
|
||||
filePattern="logs/${name}-%d{yyyy-MM-dd}-%i.log.gz">
|
||||
|
||||
<!--
|
||||
set output pattern according to the property ${pattern}
|
||||
-->
|
||||
<PatternLayout pattern="${pattern}" charset="UTF-8" />
|
||||
|
||||
<!--
|
||||
The policy to use to determine if a rollover should occur.
|
||||
|
||||
The following XML fragment defines policies that rollover the log when the log size reaches 20 megabytes, and when the current date no longer matches the log’s start date.
|
||||
-->
|
||||
<Policies>
|
||||
<TimeBasedTriggeringPolicy />
|
||||
<SizeBasedTriggeringPolicy size="20 MB" />
|
||||
</Policies>
|
||||
|
||||
<!--
|
||||
if the fileIndex attribute is set to "nomax" then the min and max values will be ignored and file numbering will increment by 1 and each rollover will have an incrementally higher value with no maximum number of files.
|
||||
-->
|
||||
<DefaultRolloverStrategy fileIndex="nomax">
|
||||
|
||||
<!--
|
||||
Cleanup
|
||||
-->
|
||||
<Delete basePath="logs" maxDepth="1">
|
||||
|
||||
<!--
|
||||
Delete oldest log files if they are older than 30 days or total accumulated size exceeds 1 GB
|
||||
-->
|
||||
<IfFileName glob="${name}-*.log.gz">
|
||||
<IfAny>
|
||||
<IfLastModified age="30d" />
|
||||
<IfAccumulatedFileSize exceeds="1 GB"/>
|
||||
</IfAny>
|
||||
</IfFileName>
|
||||
</Delete>
|
||||
</DefaultRolloverStrategy>
|
||||
</RollingFile>
|
||||
</Appenders>
|
||||
|
||||
<!--
|
||||
The top-level layer is the LOGGER which provides the Logger object. The Logger object is responsible for capturing logging information and they are stored in a namespace hierarchy.
|
||||
-->
|
||||
<Loggers>
|
||||
<!--
|
||||
set logger for class "ch.docuteam" to level "debug"
|
||||
|
||||
there is no ref, meaning that the output will be the same for each appender.
|
||||
-->
|
||||
<Logger name="ch.docuteam" level="debug" />
|
||||
|
||||
<!--
|
||||
set logger for class "ch.docuteam.feeder", which is a child for ch.docuteam, to level "debug"
|
||||
Once an event reaches a logger with its additivity set to false the event will not be passed to any of its parent loggers
|
||||
|
||||
for appender STDOUT we set to level "info"
|
||||
for appender STDERR we set to level "error"
|
||||
for appender ROLLINGFILE we use default level "info"
|
||||
-->
|
||||
<Logger name="ch.docuteam.feeder" level="debug" additivity="false">
|
||||
<AppenderRef ref="STDOUT" level="info" />
|
||||
<AppenderRef ref="STDERR" level="error" />
|
||||
<AppenderRef ref="ROLLINGFILE" />
|
||||
</Logger>
|
||||
<!-- Minimize logging for ch.docuteam.feeder.qualityassurance.SIPVirusCheck -->
|
||||
<Logger
|
||||
name="ch.docuteam.feeder.qualityassurance.SIPVirusCheck.VirusScannerClam"
|
||||
level="info" additivity="false">
|
||||
<AppenderRef ref="STDOUT" level="warn" />
|
||||
<AppenderRef ref="STDERR" level="error" />
|
||||
<AppenderRef ref="ROLLINGFILE" />
|
||||
</Logger>
|
||||
<Logger
|
||||
name="com.artofsolving.jodconverter.openoffice.connection.AbstractOpenOfficeConnection"
|
||||
level="info" />
|
||||
<Logger name="fedora.services.diringest" level="info" />
|
||||
<Logger name="org.apache.axis" level="info" />
|
||||
<Logger name="org.icepdf.core.pobjects.Catalog" level="info" />
|
||||
<!-- Avoid messages like "will always scan up to maximum bytes." -->
|
||||
<Logger
|
||||
name="uk.gov.nationalarchives.droid.core.signature.droid6.InternalSignature"
|
||||
level="error" />
|
||||
<Logger name="uk.gov.nationalarchives.droid.xmlReader"
|
||||
level="error" />
|
||||
|
||||
<!--
|
||||
Here come the default (root) outputs...
|
||||
by default, only shows messages from WARN onwards: WARN < ERROR < FATAL
|
||||
-->
|
||||
<Root level="warn">
|
||||
|
||||
<!--
|
||||
set log level of appender STDOUT to "warn".
|
||||
it actually isn't nescessary, as we defined the standard to "warn" already.
|
||||
-->
|
||||
<AppenderRef ref="STDOUT" level="warn" />
|
||||
|
||||
<!--
|
||||
set log level of appender STDERR to "error",
|
||||
because we decide that the standard "warn" is not enough.
|
||||
-->
|
||||
<AppenderRef ref="STDERR" level="error" />
|
||||
|
||||
<!--
|
||||
set log level of appender ROLLINGFILE to "debug"
|
||||
-->
|
||||
<AppenderRef ref="ROLLINGFILE" level="debug" />
|
||||
</Root>
|
||||
</Loggers>
|
||||
|
||||
</Configuration>
|
||||
```
|
||||
|
||||
## Tutorial log4j
|
||||
|
||||
https://howtodoinjava.com/log4j
|
||||
|
||||
## Example (log4j 1)
|
||||
|
||||
|
||||
```
|
||||
<!--
|
||||
|
||||
log4j
|
||||
*****
|
||||
|
||||
more infos see: https://logging.apache.org/log4j/2.x/
|
||||
|
||||
this example taken from fedoragsearch on nwvappdafed001t.adtest.noel.gv.at
|
||||
|
||||
comments by roger rutishauser -->
|
||||
|
||||
|
||||
|
||||
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
|
||||
|
||||
<!-- new configuration -->
|
||||
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<!-- The APPENDER object is responsible for publishing logging information to various preferred destinations such as a database, file, console, UNIX Syslog, etc.
|
||||
-->
|
||||
|
||||
<!-- output in console with ConsoleAppender -->
|
||||
<appender name="STDOUT" class="org.apache.log4j.ConsoleAppender">
|
||||
|
||||
<!-- The LAYOUT layer provides objects which are used to format logging information in different styles. It provides support to appender objects before publishing logging information.
|
||||
there are different ways, PatternLayout is one of them.
|
||||
more info: https://www.tutorialspoint.com/log4j/log4j_log_formatting.htm
|
||||
-->
|
||||
<layout class="org.apache.log4j.PatternLayout">
|
||||
|
||||
<!-- value explained:
|
||||
%p priority of logging event
|
||||
%d output date
|
||||
%c{1} used to output the category of the logging event
|
||||
%m output the application supplied message associated with the logging event
|
||||
%n outputs platform dependent line separator character(s)
|
||||
-->
|
||||
<param name="ConversionPattern" value="%p %d (%c{1}) %m%n"/>
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
<!-- output in file
|
||||
https://www.tutorialspoint.com/log4j/log4j_logging_files.htm
|
||||
-->
|
||||
<!-- create daily log file with DailyRollingFileAppender-->
|
||||
<appender name="FILEOUT" class="org.apache.log4j.DailyRollingFileAppender">
|
||||
<!-- path to log file -->
|
||||
<param name="File" value="${catalina.base}/logs/fedoragsearch.daily.log"/>
|
||||
<!-- beispiel: fedoragsearch.daily.log.2020-10-21 -->
|
||||
<param name=" " value="'.'yyyy-MM-dd"/>
|
||||
<layout class="org.apache.log4j.PatternLayout">
|
||||
<!-- explanation see above -->
|
||||
<param name="ConversionPattern" value="%p %d (%c{1}) %m%n"/>
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
|
||||
|
||||
<!-- create daily log file with DailyRollingFileAppender and limit to also to size -->
|
||||
<appender name="FILEOUT" class="org.apache.log4j.DailyRollingFileAppender">
|
||||
<rollingPolicy class="org.apache.log4j.rolling.TimeBasedRollingPolicy">
|
||||
|
||||
<!-- path to log file -->
|
||||
<param name="File" value="${catalina.base}/logs/fedoragsearch.daily.log"/>
|
||||
<!-- beispiel: fedoragsearch.daily.log.2020-10-21 -->
|
||||
<param name="DatePattern" value="'.'yyyy-MM-dd"/>
|
||||
</rollingPolicy>
|
||||
<triggeringPolicy class="org.apache.log4j.rolling.SizeBasedTriggeringPolicy">
|
||||
<param name="MaxFileSize" value="10MB" />
|
||||
</triggeringPolicy>
|
||||
<layout class="org.apache.log4j.PatternLayout">
|
||||
<!-- explanation see above -->
|
||||
<param name="ConversionPattern" value="%p %d (%c{1}) %m%n"/>
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
|
||||
|
||||
<!-- The top-level layer is the LOGGER which provides the Logger object. The Logger object is responsible for capturing logging information and they are stored in a namespace hierarchy.
|
||||
-->
|
||||
<logger name="dk.defxws.fedoragsearch" additivity="false">
|
||||
|
||||
<!-- The LEVEL object defines the granularity and priority of any logging information.
|
||||
For the standard levels, we have
|
||||
ALL (trace) < DEBUG < INFO < WARN < ERROR < FATAL < OFF.
|
||||
|
||||
here we get all messages from DEBUG onwards: DEBUG < INFO < WARN < ERROR < FATAL
|
||||
-->
|
||||
<level value="DEBUG" />
|
||||
<appender-ref ref="FILEOUT"/>
|
||||
</logger>
|
||||
|
||||
<logger name="dk.defxws.fgszebra" additivity="false">
|
||||
<level value="DEBUG" />
|
||||
<appender-ref ref="FILEOUT"/>
|
||||
</logger>
|
||||
|
||||
<logger name="dk.defxws.fgslucene" additivity="false">
|
||||
<level value="DEBUG" />
|
||||
<appender-ref ref="FILEOUT"/>
|
||||
</logger>
|
||||
|
||||
<logger name="dk.defxws.fgssolr" additivity="false">
|
||||
<level value="DEBUG" />
|
||||
<appender-ref ref="FILEOUT"/>
|
||||
</logger>
|
||||
|
||||
<root>
|
||||
<!-- in this file, the console output only shows messages from WARN onwards: WARN < ERROR < FATAL
|
||||
-->
|
||||
<level value="WARN" />
|
||||
<appender-ref ref="STDOUT"/>
|
||||
</root>
|
||||
|
||||
</log4j:configuration>
|
||||
```
|
||||
Loading…
Reference in New Issue
Block a user