This post is older than a year. Consider some information might not be accurate anymore.
The reasons to use logging profiles: The use of logging profiles allows administrators to create logging configuration that are specific to one or more applications without affecting any other logging configuration. Because each profile is defined in the server configuration, the logging configuration can be changed without requiring that the affected applications be redeployed.
Logging profiles are like additional logging subsystems. Each logging profile consists of three of the four notable parts listed above:
- handler configurations
- logger
- and the root logger declarations.
General steps:
- Setup JBoss - create logging profile
- Configure your Java EE app to use the created profile
Setup JBoss
Create a logging profile with CLI
# _ _
# | | ___ __ _ __ _(_)_ __ __ _
# | |/ _ \ / _` |/ _` | | '_ \ / _` |
# | | (_) | (_| | (_| | | | | | (_| |
# |_|\___/ \__, |\__, |_|_| |_|\__, |
# |___/ |___/ |___/
# create logging profile
# root configuration path /subsystem=logging/logging-profile=DEMO
# /subsystem=logging/logging-profile=DEMO:remove
/subsystem=logging/logging-profile=DEMO:add
/subsystem=logging/logging-profile=DEMO/ \
periodic-rotating-file-handler=metrics:add( \
file={ \
"path"=>"metrics.log", \
"relative-to"=>"jboss.server.log.dir" \
}, \
suffix=".yyyy-MM-dd", \
append="true", \
formatter="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n", \
autoflush="true")
/subsystem=logging/logging-profile=DEMO/ \
periodic-rotating-file-handler=metrics:write-attribute(name="level", value="DEBUG")
# log category
/subsystem=logging/logging-profile=DEMO/ \
logger=de.test:add(level=DEBUG)
/subsystem=logging/logging-profile=DEMO/ \
logger=de.test:add-handler(name="metrics")
# custom pattern
/subsystem=logging/logging-profile=DEMO/ \
pattern-formatter=stat-pattern:add( \
pattern="A,%d{yyyy-MM-dd'T'HH:mm:ss.SSS} %m%n") /subsystem=logging/logging-profile=DEMO/ \
periodic-rotating-file-handler=metrics:write-attribute(name=named-formatter, value=stat-pattern)
# _ _
# _ __ ___ ___ | |_ | | ___ __ _ __ _ ___ _ __
# | '__/ _ \ / _ \| __| | |/ _ \ / _` |/ _` |/ _ \ '__|
# | | | (_) | (_) | |_ | | (_) | (_| | (_| | __/ |
# |_| \___/ \___/ \__| |_|\___/ \__, |\__, |\___|_|
# |___/ |___/
# set level of root logger
/subsystem=logging/logging-profile=DEMO/ \
root-logger=ROOT:add
/subsystem=logging/logging-profile=DEMO/ \
root-logger=ROOT:write-attribute(name="level", value="DEBUG")
/subsystem=logging/logging-profile=DEMO/ \
root-logger=ROOT:root-logger-assign-handler(name="CONSOLE")
/subsystem=logging/logging-profile=DEMO/ \
root-logger=ROOT:root-logger-assign-handler(name="metrics")
Configure your Java EE Application
You can assign a logging profile to a deployment via the deployments manifest. Add a Logging-Profile entry to the MANIFEST.
Create MANIFEST.MF
Manifest-Version: 1.0
Logging-Profile: DEMO
Configure Maven to include manifest file
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<archive>
<manifestFile>src/main/resources/META-INF/MANIFEST.MF</manifestFile>
</archive>
</configuration>
</plugin>