Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagexml
titleController log4j2.xml
linenumberstrue
collapsetrue
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN" shutdownHook="disable">
	<Properties>
		<Property name="TimeZone">${env:JS7_CONTROLLER_TZ:-Etc/UTC}</Property>
		<Property name="LogDir">${env:JS7_CONTROLLER_LOGS:-logs}</Property>
		<Property name="LogBasename">${env:JS7_CONTROLLER_APPNAME:-controller}</Property>
		
		<Property name="RetainDays">30d</Property>
		<Property name="MaxSizeOfRolledOverFiles">5GB</Property>
		<Property name="MaxSizePerFile">100MB</Property>
		
		<!-- Log level of the Root Logger. -->
		<Property name="RootLogLevel">INFO</Property>
		
		<!-- Configuration for a 2nd debug log file (OFF|DEBUG|TRACE) 
			 If this value is set to DEBUG or TRACE then the above 
			 RootLogLevel has to have the same value.
		-->
		<Property name="LogLevelOfDebugLog">OFF</Property>
		
	</Properties>
	
	<Appenders>
		<Console name="console" target="SYSTEM_ERR">
			<PatternLayout pattern="%highlight{%d{EE HH:mm:ss.SSS}{${TimeZone}} %-5level{INFO=info, DEBUG=debug, TRACE=trace} %logger - %message}{WARN=magenta}%n"/>
		</Console>
		
		<RollingRandomAccessFile name="fileInfo"
				fileName="${LogDir}/${LogBasename}.log"
				filePattern="${LogDir}/${LogBasename}-%d{yyyy-MM-dd}-%i.log.gz"
				immediateFlush="false">
			<PatternLayout pattern="%d{ISO8601}{${TimeZone}} %-5level{INFO=info, DEBUG=debug, TRACE=trace} %logger - %message%n"
					charset="UTF-8"/>
			<Policies>
				<TimeBasedTriggeringPolicy/>
				<SizeBasedTriggeringPolicy size="${MaxSizePerFile}"/>
			</Policies>
			<DefaultRolloverStrategy fileIndex="nomax">
				<Delete basePath="${LogDir}/" followLinks="true">
					<IfFileName glob="${LogBasename}-*.log.gz" >
						<IfAny>
							<IfLastModified age="${RetainDays}" />
							<IfAccumulatedFileSize exceeds="${MaxSizeOfRolledOverFiles}"/>
						</IfAny>
					</IfFileName>
				</Delete>
			</DefaultRolloverStrategy>
		</RollingRandomAccessFile>
		
		<RollingRandomAccessFile name="fileDebug"
				fileName="${LogDir}/${LogBasename}-debug.log"
				filePattern="${LogDir}/${LogBasename}-debug-%d{yyyy-MM-dd}-%i.log.gz"
				immediateFlush="false">
			<PatternLayout pattern="%d{ISO8601}{${TimeZone}} %-5level{INFO=info, DEBUG=debug, TRACE=trace} %logger - %message%n"
					charset="UTF-8"/>
			<Policies>
				<TimeBasedTriggeringPolicy/>
				<SizeBasedTriggeringPolicy size="${MaxSizePerFile}"/>
			</Policies>
			<DefaultRolloverStrategy fileIndex="nomax">
				<Delete basePath="${LogDir}/" followLinks="true">
					<IfFileName glob="${LogBasename}-*.log.gz" >
						<IfAny>
							<IfLastModified age="${RetainDays}" />
							<IfAccumulatedFileSize exceeds="${MaxSizeOfRolledOverFiles}"/>
						</IfAny>
					</IfFileName>
				</Delete>
			</DefaultRolloverStrategy>
		</RollingRandomAccessFile>
	</Appenders>
	
	<Loggers>
		<Logger name="spray" level="INFO"/>
		<Logger name="akka" level="INFO"/>
		<Logger name="akka.event.slf4j.Slf4jLogger" level="WARN"/>
		<Logger name="js7.common.akkahttp.web.auth.GateKeeper" level="ERROR"/>
		<Root level="${RootLogLevel}">
			<!--AppenderRef ref="console" level="ERROR"/-->
			<AppenderRef ref="fileInfo" level="INFO"/>
			<AppenderRef ref="fileDebug" level="${LogLevelOfDebugLog}"/>
		</Root>
	</Loggers>
</Configuration>

Explanation:

  • The Controller and Agent Log4j2 configuration file is the same for Controllers and Agents except files are the same except for the fact that environment variables in lines 4-6 for Agents use:
    • <Property name="TimeZone">${env:JS7_AGENT_TZ:-Etc/UTC}</Property>
      <Property name="LogDir">${env:JS7_AGENT_LOGS:-logs}</Property>
      <Property name="LogBasename">${env:JS7_AGENT_APPNAME:-agent}</Property>
  • To modify the time zone that is applied to log entries and the point in time when log rotation occurs, modify <Property name="TimeZone">Etc/UTC</Property>. The time zone is specified by the Controller and Agent start scripts that set the environment variables JS7_CONTROLLER_TZ and JS7_AGENT_TZ respectively from the time zone reported by the operating system.
  • To enable the debug mode, change the <property name="RootLogLevel">INFO</property> and <property name="LogLevelOfDebugLog">OFF</property> to DEBUG.
  • To change the log retention period, modify <Property name="RetainDays">30d</Property> to some other value. Note the use of the suffixes d(ays), w(eeks), m(onths).
  • To limit the max. size of individual log files, modify <Property name="MaxSizePerFile">100MB</Property> to some other value. Note the use of the units MB, GB.
  • To limit the storage consumption of all log files, modify <Property name="MaxSizeOfRolledOverFiles">5GB</Property> to some other value. Note the use of the units MB, GB.

...