-
Notifications
You must be signed in to change notification settings - Fork 7
Log4jMojo
The log4j mojo can be used to generate a log4j.properties from dependencies. It generates a standard log4j header and adds snippets generated with
the deegree annotation processor.
In order to generate the needed snippets, you'll need to annotate your classes with the annotations from the deegree-core-annotations module.
There are two relevant annotations, on package and on class level.
You can annotate packages by adding the @PackageLoggingNotes annotation to the package in your package-info.java:
@PackageLoggingNotes(title = "2D rendering")
package org.deegree.rendering.r2d;
import org.deegree.commons.annotations.PackageLoggingNotes;This will result in a comment header using the specified title.
Here's a class level example:
package org.deegree.example;
import org.deegree.commons.annotations.LoggingNotes;
@LoggingNotes(warn = "log info about some problem", info = "log some general info")
public class SomeClass {
...This will result in comments with the text, and a commented log4j line configuring the class for the specified log level. In the example:
# log info about some problem
#log4j.logger.org.deegree.example.SomeClass = WARN
# log some general info
#log4j.logger.org.deegree.example.SomeClass = INFOYou can specify almost all log4j log levels like error, warn, info, debug and trace.
Note that these parameters are also possible on package level (generating a package level log4j example line).
If you add the compiler argument -Alog4j.outputdir=${project.basedir}/target/classes/META-INF/deegree/log4j/ to your module (with
deegree-core-annotations on the classpath), an appropriate snippet for use by this mojo is generated automatically.
The usage of the mojo itself is then easy, these lines generate a log4j.properties in target/generated-resources in the generate-resources
phase (if no log4j.properties exists in src/main/resources:
<plugin>
<groupId>org.deegree</groupId>
<artifactId>deegree-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>assemble-log4j</goal>
</goals>
</execution>
</executions>
</plugin>The following configuration options change the behaviour:
-
width: max line width (default is 120) -
deegreeLoggingLevel: log level fororg.deegree(default isINFO) -
rootLoggingLevel: root logger level (default isERROR)