How to Enable Slf4j Logging in Glassfish
This blog entry will try to setup slf4j as the main logger for glassfish 3.1.1 What you need: 1.) Glassfish 3.1.1 (zipped) 2.) Download...
https://www.czetsuyatech.com/2012/05/javaee-enable-slf4j-logging-on-glassfish.html
This blog entry will try to setup slf4j as the main logger for glassfish 3.1.1
What you need:
1.) Glassfish 3.1.1 (zipped)
2.) Download the ff jars:
a.) slf4j-api.jar
b.) jul-to-slf4j.jar
c.) logback-classic.jar
d.) logback-core.jar
Steps
1.) Extract glassfish in the directory of your choice
2.) Copy the jars mentioned above in {glassfish_home}/glassfish/lib/endorsed.
3.) Modify domain.xml in {glassfish_home}/glassfish/domains/domain1/config/domain.xml. We assume that you did not create another domain for this exercise.
4.) In the "java-config" section add the ff "jvm-options":
The above 2 statements will configure logger and forward the logging statement to logback.
Content of _logging.properties
What you need:
1.) Glassfish 3.1.1 (zipped)
2.) Download the ff jars:
a.) slf4j-api.jar
b.) jul-to-slf4j.jar
c.) logback-classic.jar
d.) logback-core.jar
Steps
1.) Extract glassfish in the directory of your choice
2.) Copy the jars mentioned above in {glassfish_home}/glassfish/lib/endorsed.
3.) Modify domain.xml in {glassfish_home}/glassfish/domains/domain1/config/domain.xml. We assume that you did not create another domain for this exercise.
4.) In the "java-config" section add the ff "jvm-options":
<jvm-options>-Dlog4j.configuration=file:///${com.sun.aas.instanceRoot}/config/_logging.properties</jvm-options>
<jvm-options>-Dlogback.configurationFile=file:///${com.sun.aas.instanceRoot}/config/logback.xml</jvm-options>
The above 2 statements will configure logger and forward the logging statement to logback.
Content of _logging.properties
handlers = org.slf4j.bridge.SLF4JBridgeHandler
com.sun.enterprise.server.logging.GFFileHandler.flushFrequency=1
com.sun.enterprise.server.logging.GFFileHandler.file=${com.sun.aas.instanceRoot}/logs/server.log
com.sun.enterprise.server.logging.GFFileHandler.rotationTimelimitInMinutes=0
com.sun.enterprise.server.logging.GFFileHandler.logtoConsole=false
com.sun.enterprise.server.logging.GFFileHandler.rotationLimitInBytes=2000000
com.sun.enterprise.server.logging.GFFileHandler.alarms=false
com.sun.enterprise.server.logging.GFFileHandler.formatter=com.sun.enterprise.server.logging.UniformLogFormatter
com.sun.enterprise.server.logging.GFFileHandler.retainErrorsStasticsForHours=0
logback.xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</Pattern>
</layout>
</appender>
<logger name="com.sido">
<level value="debug" />
</logger>
<logger name="org.springframework">
<level value="debug" />
</logger>
<root>
<level value="debug" />
<appender-ref ref="console" />
</root>
</configuration>




1 comment
Hi guys,
Could you please tell me Do I need to create logback.xml and _logging.properties by hand?
If I need so where to put them? ex: in my war file, or in {glassfish_home}/glassfish/domains/domain1/config/ ....
Thanks in advance,
Post a Comment