Logging configuration
Webswing uses Apache Log4j 2 for its application logs. The default configuration rotates each log after it reaches 100 MB and keeps five archives. You can provide an external log4j2.xml to change log levels, filenames, rotation, compression, and retention without modifying the Webswing archives.
The webswing.sh and sessionpool.sh scripts also capture process standard output and standard error and rotate that output independently. This script-managed output (for example, webswing.out) is not controlled by log4j2.xml. If Webswing is started by systemd, a servlet container, or another process manager, configure standard-output retention in that system separately.
Default configuration files
Each Webswing process has its own Log4j 2 configuration and log files:
| Process | Configuration inside the distribution | Default log files |
|---|---|---|
| Webswing Server / Cluster Server | webswing-server.war/WEB-INF/classes/log4j2.xml |
webswing.log, stats.log, audit.log |
| Admin Console | webswing-admin-server.war/WEB-INF/classes/log4j2.xml |
admin.log, autoscaling.log |
| Cluster Session Pool | webswing.war/WEB-INF/lib-ext/webswing-cluster-sessionpool-<version>.jar!/log4j2.xml |
webswing-session-pool.log |
The Session Pool configuration is packaged inside a JAR nested in webswing.war, which is why searching only the extracted WAR entries does not show the webswing-session-pool.log filename directly. Extract the nested JAR to obtain its default log4j2.xml.
Log files are written under ${sys:webswing.logsDir:-logs/}. Set the directory with the webswing.logsDir JVM system property, for example:
java -Dwebswing.logsDir=/var/log/webswing/ -jar server/webswing-jetty-launcher.jar
The directory must exist and be writable by the account running Webswing. Keep the trailing path separator when overriding this property because the default configurations append filenames directly to its value.
Use an external Log4j 2 configuration
- Extract the applicable
log4j2.xmlfrom the WAR or JAR listed above. - Save the customized file outside the Webswing distribution so that an upgrade does not overwrite it.
- Add
-Dlog4j.configurationFile=<path-to-log4j2.xml>to the JVM that runs the component. - Restart that component.
For example, when starting the Webswing Server directly:
java \
-Dlog4j.configurationFile=/etc/webswing/log4j2-server.xml \
-jar server/webswing-jetty-launcher.jar
With the supplied startup scripts or Docker images, include the property in WEBSWING_JAVA_OPTS. Preserve any existing JVM options in that variable:
WEBSWING_JAVA_OPTS="-Xmx2g -Dlog4j.configurationFile=/etc/webswing/log4j2-server.xml" \
./webswing.sh start
Configure a separately running Cluster Session Pool in the same way, but point its JVM to the external copy of the Session Pool's log4j2.xml:
WEBSWING_JAVA_OPTS="-Xmx2g -Dlog4j.configurationFile=/etc/webswing/log4j2-session-pool.xml" \
./sessionpool.sh start
The configuration property applies to one JVM. In a clustered installation, add the appropriate property and configuration file to every Server, Admin Console, and Session Pool process that you want to customize. For deployment in an external servlet container, add it to that container's JVM options.
Daily rotation, compression, and retention
The following RollingFile appender rotates webswing.log at midnight, compresses archives with gzip, and deletes archives older than 15 days:
<RollingFile name="R"
fileName="${sys:webswing.logsDir:-logs/}webswing.log"
filePattern="${sys:webswing.logsDir:-logs/}webswing-%d{yyyy-MM-dd}.log.gz">
<PatternLayout pattern="%d %-5p [%t] %m%n" />
<Policies>
<TimeBasedTriggeringPolicy interval="1" modulate="true" />
</Policies>
<DefaultRolloverStrategy>
<Delete basePath="${sys:webswing.logsDir:-logs/}" maxDepth="1">
<IfFileName glob="webswing-*.log.gz">
<IfLastModified age="15d" />
</IfFileName>
</Delete>
</DefaultRolloverStrategy>
</RollingFile>
To rotate stats.log daily as well, make the equivalent change to appender S while retaining its existing layout and buffering settings:
<RollingFile name="S"
fileName="${sys:webswing.logsDir:-logs/}stats.log"
filePattern="${sys:webswing.logsDir:-logs/}stats-%d{yyyy-MM-dd}.log.gz"
bufferedIO="true" bufferSize="16384" immediateFlush="false">
<PatternLayout pattern="%d{dd-MMM-yyyy-HH:mm:ss.SSS},%m%n" />
<Policies>
<TimeBasedTriggeringPolicy interval="1" modulate="true" />
</Policies>
<DefaultRolloverStrategy>
<Delete basePath="${sys:webswing.logsDir:-logs/}" maxDepth="1">
<IfFileName glob="stats-*.log.gz">
<IfLastModified age="15d" />
</IfFileName>
</Delete>
</DefaultRolloverStrategy>
</RollingFile>
The same policy can be applied to the audit.log, Admin Console, and Session Pool appenders by changing fileName, filePattern, and the cleanup glob. See the Log4j 2 documentation for RollingFile appenders and delete actions for additional policies.
DefaultRolloverStrategy max="15" alone does not retain 15 archives when filePattern contains a date but no %i index. Use a Delete action, as above, for time-based retention.