Skip to content

Logging

EmailRequest uses the Apache Log4j version 2 framework for its logging. By default EmailRequest looks for a file named log4j2.xml in the same folder as itself, if no such file is found EmailRequest defaults to a built in generic version of log4j2.xml. The standard log4j2.xml that is included in the EmailRequest package at downloadportal.easit.com looks as shown below. Feel free to copy and use this example if you need to.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="INFO">
  <Properties>
    <Property name="log-path">Logs</Property>
    <Property name="default-log-pattern">%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level - %m [%c]%n</Property>
    <Property name="default-max-log-files">30</Property>
    <Property name="default-log-name">emailrequest</Property>
 </Properties>
 <Appenders>
  <Console name="STDOUT" target="SYSTEM_OUT">
   <PatternLayout pattern="${default-log-pattern}"/>
  </Console>
  <RollingFile name="FILE" fileName="${log-path}/${default-log-name}.log"
   filePattern="${log-path}/${default-log-name}-%d{yyyy-MM-dd}.log">
   <PatternLayout>
    <pattern>${default-log-pattern}</pattern>
   </PatternLayout>
   <Policies>
    <TimeBasedTriggeringPolicy interval="1" modulate="true"/>
   </Policies>
   <DefaultRolloverStrategy>
    <Delete basePath="${log-path}" maxDepth="1">
     <IfFileName glob="${default-log-name}-2*.log" />
     <IfAccumulatedFileCount exceeds="${default-max-log-files}" />
    </Delete>
   </DefaultRolloverStrategy>
  </RollingFile>
  <RollingFile name="FILETRACE" fileName="${log-path}/${default-log-name}-trace.log"
   filePattern="${log-path}/${default-log-name}-trace-%d{yyyy-MM-dd}.log">
   <PatternLayout>
    <pattern>${default-log-pattern}</pattern>
   </PatternLayout>
   <Policies>
    <TimeBasedTriggeringPolicy interval="1" modulate="true"/>
   </Policies>
   <Filters>
    <!-- Deny DEBUG and above & allow TRACE -->
    <ThresholdFilter level="DEBUG" onMatch="DENY" onMismatch="NEUTRAL"/>
     <ThresholdFilter level="TRACE" onMatch="ACCEPT" onMismatch="DENY"/> 
   </Filters>
   <DefaultRolloverStrategy>
    <Delete basePath="${log-path}" maxDepth="1">
     <IfFileName glob="${default-log-name}-trace-2*.log" />
     <IfAccumulatedFileCount exceeds="${default-max-log-files}" />
    </Delete>
   </DefaultRolloverStrategy>
  </RollingFile>
 </Appenders>

 <Loggers>
  <Root level="INFO">
   <appender-ref ref="STDOUT" level="DEBUG"/>
   <appender-ref ref="FILETRACE" level="TRACE"/>
  </Root>
 </Loggers>
</Configuration>

Elements / Properties and Attributes of interest

Configuration/Properties

  • log-path - Relative path where logs are stored.
  • default-log-pattern - Specifies the layout within the log. Can be customized to better match a log collecting system.
  • default-max-log-files - How many log files are saved. When this value is reached the oldest will be removed.
  • default-log-name - Name of log file and trace log file.

Configuration/Appenders/RollingFile name="FILE"

  • Attribute:fileName - Full path and name to log file.
  • Attribute:filePattern - Pattern for log file name when rotating logs.

Configuration/Appenders/RollingFile name="FILETRACE"

  • Attribute:fileName - Full path and name to trace log file.
  • Attribute:filePattern - Pattern for log file name when rotating trace logs.

Configuration/Loggers/Root

  • Attribute:level - Base level for all logging
  • appender-ref - Can be used to override the base level logging for each appender.

In our example above INFO-level and higher messages are logged to emailrequest.log, TRACE-level and higher messages are logged to emailrequest-trace.log and if you are running EmailRequest in a console you will get DEBUG-level and higher messages.