Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change logging framwork from log4j2 to logback #1705

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions deegree-core/deegree-core-test-logging/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

<dependencies>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j2-impl</artifactId>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</dependency>
</dependencies>

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%date %level %logger{1} [%thread] %msg%n</pattern>
</encoder>
</appender>

<!-- level: TRACE > DEBUG > INFO > WARN > ERROR > OFF -->

<logger name="org.deegree" level="WARN"/>
<logger name="org.deegree.commons.utils.net" level="DEBUG"/>
<logger name="org.deegree.services.wms" level="DEBUG"/>
<!--
<logger name="org.deegree.geometry.standard.AbstractDefaultGeometry" level="OFF"/>
-->

<logger name="org.apache.http" level="ERROR"/>
<logger name="org.apache.http.wire" level="OFF"/>

<logger name="net.sf.saxon" level="WARN"/>
<logger name="com.galdosinc" level="WARN"/>
<logger name="com.occamlab" level="WARN"/>

<root level="INFO">
<appender-ref ref="STDOUT" />
</root>
</configuration>
87 changes: 45 additions & 42 deletions deegree-documentation/src/main/asciidoc/logging.adoc
Original file line number Diff line number Diff line change
@@ -1,72 +1,75 @@
[[anchor-logging-configuration]]
=== Logging configuration

The deegree webservices do use the https://logging.apache.org/log4j/2.x[Apache Log4j 2 framework] for logging. The configuration of the logging submodule can be stored in XML, YAML, JSON, or properties format.
The web application contains a default configuration file _/WEB-INF/classes/log4j2.properties_ with two appenders, one logging to the console Stdout (`System.out`) and the other writes the log messages into a file _logs/deegree.log_.
The deegree webservices do use the https://logback.qos.ch[Logback Project] for logging. The configuration of the logging submodule is stored in XML format.
The web application contains a default configuration file _/WEB-INF/classes/logback.xml_ with two appenders, one logging to the console Stdout (`System.out`) and the other writes the log messages into a file _logs/deegree.log_.

The configuration in a nutshell:

The console appender is configured with:

[source,properties]
[source,xml]
----
appender.console.type = Console <1>
appender.console.name = STDOUT
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = %d %p %C{1.} [%t] %m%n <2>
appender.console.filter.threshold.type = ThresholdFilter
appender.console.filter.threshold.level = info <3>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> <1>
<encoder>
<pattern>%date %level %logger{1} [%thread] %msg%n</pattern> <2>
</encoder>
<!--
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>INFO</level> <3>
</filter>
-->
</appender>
----
<1> defines the type of the appender
<2> defines the pattern for formatting the log message
<3> defines the threshold for this appender
<3> defines the threshold for this appender (In this example, it's disabled/commented out)

The file appender is configured with:

[source,properties]
[source,xml]
----
appender.rolling.type = RollingFile <1>
appender.rolling.name = RollingFile
appender.rolling.fileName = ${logpath}/${filename} <2>
appender.rolling.filePattern = ${logpath}/deegree-%d{MM-dd-yyyy}-%i.log.gz <3>
appender.rolling.layout.type = PatternLayout
appender.rolling.layout.pattern = %d %p %C{1.} [%t] %m%n <4>
appender.rolling.policies.type = Policies <5>
appender.rolling.policies.time.type = TimeBasedTriggeringPolicy
appender.rolling.policies.time.interval = 1
appender.rolling.policies.time.modulate = true
appender.rolling.policies.size.type = SizeBasedTriggeringPolicy
appender.rolling.policies.size.size=100MB
appender.rolling.strategy.type = DefaultRolloverStrategy
appender.rolling.strategy.max = 10
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> <1>
<file>${log.dir}/${log.prefix}.log</file> <2>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy"> <3>
<fileNamePattern>${log.dir}/${log.prefix}-%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern> <4>
<maxFileSize>100MB</maxFileSize>
<maxHistory>20</maxHistory>
<totalSizeCap>1GB</totalSizeCap>
</rollingPolicy>
<!--
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>INFO</level> <6>
</filter>
-->
<encoder>
<pattern>%date %level %logger{1} [%thread] %msg%n</pattern> <5>
</encoder>
</appender>
----
<1> defines the type of the appender
<2> defines the file name
<3> defines the format of the archived file names, when the policies are applied
<4> defines the pattern for formatting the log message
<5> defines the policies when rolling over the files, triggered by size (>100MB) and time (> 1 day)
<3> defines the policies when rolling over the files, triggered by size (>100MB) and time (> 1 day)
<4> defines the format of the archived file names, when the policies are applied
<5> defines the pattern for formatting the log message
<6> defines the threshold for this appender (In this example, it's disabled/commented out)

The log file name is defined by the following settings:

[source,properties]
[source,xml]
----
property.filename = deegree.log
property.logpath = ${sys:log.dir:-logs} <1>
<variable name="log.prefix" value="deegree" /> <1>
<variable name="log.dir" value="logs"/> <2>
----
<1> defines the log directory, default is _logs/_ and can be defined by an environment variable `log.dir`
<1> defines the prefix of the logfiles, default is _deegree_ and can be defined by an environment variable `log.prefix`
<2> defines the log directory, default is _logs/_ and can be defined by an environment variable `log.dir`

To turn off or on a specific logger use the logger definition as in the following example for `org.deegree`:

[source,properties]
[source,xml]
----
logger.org.deegree.name = org.deegree <1>
logger.org.deegree.level = info <2>
logger.org.deegree.additivity = false
logger.org.deegree.appenderRef.rolling.ref = RollingFile <3>
logger.org.deegree.appenderRef.stdout.ref = STDOUT <3>
<logger name="org.deegree" level="INFO"/> <1>
----
<1> defines the logger name, here all logger with names starting with `org.deegree` are affected
<2> defines the threshold for this logger
<3> defines the appender used by this logger
<1> defines the logger name and threshold which are applied to all logger starting with `org.deegree`

You will find more information about Apache Log4j configuration in the https://logging.apache.org/log4j/2.x/manual/[Log4j 2 manual].
You will find more information about Logback configuration in the https://logback.qos.ch/documentation.html[Logback documentation].
28 changes: 2 additions & 26 deletions deegree-services/deegree-webservices/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,30 +34,6 @@
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-resources</id>
<phase>generate-sources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/${project.artifactId}-${project.version}/WEB-INF/classes</outputDirectory>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/log4j2.properties</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
Expand Down Expand Up @@ -301,8 +277,8 @@
<artifactId>jul-to-slf4j</artifactId>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j2-impl</artifactId>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</dependency>
<dependency>
<groupId>jakarta.annotation</groupId>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<configuration>
<variable name="log.prefix" value="deegree"/>
<variable name="log.dir" value="logs"/>

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%date %level %logger{1} [%thread] %msg%n</pattern>
</encoder>
<!--
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>INFO</level>
</filter>
-->
</appender>

<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${log.dir}/${log.prefix}.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${log.dir}/${log.prefix}-%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
<maxFileSize>100MB</maxFileSize>
<maxHistory>20</maxHistory>
<totalSizeCap>1GB</totalSizeCap>
</rollingPolicy>
<!--
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>INFO</level>
</filter>
-->
<encoder>
<pattern>%date %level %logger{1} [%thread] %msg%n</pattern>
</encoder>
</appender>

<logger name="org.deegree" level="INFO"/>

<root level="INFO">
<appender-ref ref="STDOUT" />
<appender-ref ref="FILE" />
</root>
</configuration>
4 changes: 2 additions & 2 deletions deegree-tools/deegree-tools-3d/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j2-impl</artifactId>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</dependency>
</dependencies>

Expand Down
20 changes: 0 additions & 20 deletions deegree-tools/deegree-tools-3d/src/main/config/log4j2.properties

This file was deleted.

15 changes: 15 additions & 0 deletions deegree-tools/deegree-tools-3d/src/main/config/logback.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%date %level %logger{1} [%thread] %msg%n</pattern>
</encoder>
</appender>

<!--
<logger name="org.deegree" level="INFO"/>
-->

<root level="WARN">
<appender-ref ref="STDOUT" />
</root>
</configuration>
4 changes: 2 additions & 2 deletions deegree-tools/deegree-tools-base/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j2-impl</artifactId>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</dependency>
</dependencies>

Expand Down
20 changes: 0 additions & 20 deletions deegree-tools/deegree-tools-base/src/main/config/log4j2.properties

This file was deleted.

Loading