Skip to content

Logging

Kilemonn edited this page Oct 16, 2024 · 2 revisions

By default the application only outputs logs to stdout. The underlying logging library is log4cxx, so if you want logs to be saved to a log file you will need to provide a log4cxx.properties file.

Because the application already has the console appender configured, you only need to configure your required file appenders here.

Please refer to the log4cxx official docs for more configuration options and information.

An example is here (change the root log level and file log level as required):

# Root log level + adding file appender
log4j.rootLogger=INFO,file

# File appender configuration
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=socket-forwarder.log
log4j.appender.file.MaxFileSize=100KB
log4j.appender.file.MaxBackupIndex=1
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} [%-5p] %m%n
log4j.appender.file.threshold=INFO

This then needs to be added into the container at the following directory: /socket-forwarder and the appropriate environment variable outlining the properties file needs to be defined.

An example docker file is as follows:

FROM kilemon/socket-forwarder:latest

# Copy in properties file into same directory as the executable
COPY log.properties /socket-forwarder/log.properties

# Since the properties file name is not `log4cxx.properties` you need to specify the configuration file in the environment variable
ENV log4j.configuration=/socket-forwarder/log.properties

# Example TCP listening port
EXPOSE 34765/tcp

Clone this wiki locally