Skip to content

Logging

ImportClient uses the Apache Log4j version 2 framework for its logging. By default ImportClient looks for a file named log4j2.xml in the same folder as itself, if no such file is found ImportClient defaults to a built in generic version of log4j2.xml. The standard log4j2.xml that is included in the ImportClient 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
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="INFO">
    <Properties>
        <Property name="default-log-dir">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-age">30</Property>
        <Property name="default-log-name">importclient</Property>
    </Properties>
    <Appenders>
        <Console name="STDOUT" 
                 target="SYSTEM_OUT">
            <PatternLayout pattern="${default-log-pattern}"/>
        </Console>
        <RollingFile name="LOGFILE"
                     fileName="${default-log-dir}/${default-log-name}.log"
                     filePattern="${default-log-dir}/${default-log-name}-%d{yyyy-MM-dd}.log">
            <PatternLayout pattern="${default-log-pattern}"
                           charset="UTF-8"/>
            </PatternLayout>
            <Policies>
                <TimeBasedTriggeringPolicy interval="1" 
                                           modulate="true"/>
                <SizeBasedTriggeringPolicy size="1000 KB" />
            </Policies>
            <DefaultRolloverStrategy>
                <Delete basePath="${default-log-dir}" 
                        maxDepth="1">
                    <IfFileName glob="${default-log-name}-*.log" />
                    <IfLastModified age="P${default-max-log-age}D" />
                </Delete>
            </DefaultRolloverStrategy>
        </RollingFile>

    </Appenders>

    <Loggers>
      <Logger name="org.springframework" level="ERROR">
      </Logger>
      <Logger name="org.springframework.beans.factory.support.DefaultListableBeanFactory" level="WARN">
      </Logger>
      <Logger name="org.springframework.beans.factory.xml.XmlBeanDefinitionReader" level="WARN">
      </Logger>
      <Logger name="org.springframework.context.support.ClassPathXmlApplicationContext" level="WARN">
      </Logger>
      <Root level="INFO">
        <AppenderRef ref="STDOUT" level="DEBUG"/>
        <AppenderRef ref="LOGFILE"/>
      </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-max-log-age - How long 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 importclient.log and if you are running ImportClient in a console you will get DEBUG-level and higher messages.