7. Logging
Overview
Granite Data Services uses log4j or, when log4j is not available, it switches back to the standard JDK logging to display debugging informations.
While log4j.jar is already bundled with JBoss and available automatically in the classpath, it is not packaged by default in Tomcat or in some other servlet containers as well. If you are deploying your GDS applications to Tomcat, it is better to add a log4j.jar to your <MY_WAR>/WEB-INF/lib directory.
If you need other logging implementation support, you may extend the org.granite.logging.Logger abstract class and register your custom logger with the org.granite.logger.impl system property:
java ... -Dorg.granite.logger.impl=path.to.my.CustomLogger ...
Look at the org.granite.logging.Logger class and default implementations for details.
Configuration
JBoss
Edit <JBOSS_HOME>/server/default/conf/[jboss-]log4j.xml and make the following changes:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false"> ... <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender"> ... <!-- change console threshold to "DEBUG" --> <param name="Threshold" value="DEBUG"/> ... </appender> ... <!-- insert those 3 categories before the "root" node --> <category name="org"> <priority value="INFO" /> </category> <category name="com"> <priority value="INFO" /> </category> <category name="org.granite.messaging.webapp.AMFMessageServlet"> <priority value="DEBUG" /> </category> <root> <appender-ref ref="CONSOLE"/> ... </root> ... </log4j:configuration>
Tomcat
Put a new log4j.xml in the <MY_WAR>/WEB-INF/classes directory; create this directory if it does not exist. Your log4j.xml file could look like the following:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false"> <appender name="FILE" class="org.apache.log4j.RollingFileAppender"> <param name="File" value="${catalina.home}/logs/graniteds-pojo.log"/> <param name="Threshold" value="INFO"/> <param name="Append" value="false"/> <param name="MaxFileSize" value="1MB"/> <param name="MaxBackupIndex" value="1"/> <layout class="org.apache.log4j.PatternLayout"> <param name="ConversionPattern" value="%d %-5p %X{service} %X{user} [%c] %m%n"/> </layout> </appender> <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender"> <param name="Target" value="System.out"/> <param name="Threshold" value="DEBUG"/> <layout class="org.apache.log4j.PatternLayout"> <param name="ConversionPattern" value="%d{ABSOLUTE} %-5p %X{service} %X{user} [%c{1}] %m%n"/> </layout> </appender> <category name="org.granite"> <priority value="INFO" /> </category> <category name="org.granite.messaging.webapp.AMFMessageServlet"> <priority value="DEBUG" /> </category> <root> <appender-ref ref="CONSOLE"/> <appender-ref ref="FILE"/> </root> </log4j:configuration>
Sample Output
Here is a sample of what you will see after activating logging:
16:48:43,328 DEBUG [AMFMessageServlet] >> Processing AMF0 request:
org.granite.messaging.amf.AMF0Message {
version = 3
headers = []
bodies = [
org.granite.messaging.amf.AMF0Body {
target = null
serviceName = null
serviceMethodName = null
response = /3
type = ARRAY
value = [
flex.messaging.messages.CommandMessage {
messageRefType: null
operation: LOGIN
correlationId =
destination =
headers = {DSId=7ECE0DE5-3DC6-4067-95AC-1C63CADAB6FF}
messageId = 5A17A814-37C8-224B-651C-12735A309D61
timestamp = 0
clientId = null
timeToLive = 0
body = ****** (credentials)
}
]
},
org.granite.messaging.amf.AMF0Body {
target = null
serviceName = null
serviceMethodName = null
response = /4
type = ARRAY
value = [
flex.messaging.messages.RemotingMessage {
source = null
operation = findAllPersons
correlationId = null
destination = person
headers = {DSId=7ECE0DE5-3DC6-4067-95AC-1C63CADAB6FF, DSEndpoint=my-graniteamf}
messageId = 98ADE9D1-2B42-DD9A-1864-12735A407C86
timestamp = 0
clientId = 87FD89FF-2FC3-4B43-A4B6-08F0C61AEE2C
timeToLive = 0
body = []
}
]
}
]
}
16:48:44,078 DEBUG [AMFMessageServlet] << Returning AMF0 response:
org.granite.messaging.amf.AMF0Message {
version = 3
headers = []
bodies = [
org.granite.messaging.amf.AMF0Body {
target = /3/onResult
serviceName = null
serviceMethodName = null
response =
type = AMF3_OBJECT
value = flex.messaging.messages.AcknowledgeMessage {
correlationId = 5A17A814-37C8-224B-651C-12735A309D61
destination = null
headers = {}
messageId = 3DCC44CE-D163-45FB-904B-4E7EC3AB5E02
timestamp = 1185720523468
clientId = B62463FB-C477-4535-864F-E91C63093A16
timeToLive = 0
body = success
}
},
org.granite.messaging.amf.AMF0Body {
target = /4/onResult
serviceName = null
serviceMethodName = null
response =
type = AMF3_OBJECT
value = flex.messaging.messages.AcknowledgeMessage {
correlationId = 98ADE9D1-2B42-DD9A-1864-12735A407C86
destination = null
headers = {}
messageId = F61FABF6-A71B-493C-A15E-9BC6D289973F
timestamp = 1185720524078
clientId = 67EBFD5C-CF20-426D-9F66-2BA14BE9B893
timeToLive = 0
body = [test.granite.ejb3.entity.Person@30af1099]
}
}
]
}
Quick Legend
[...] means: array or List and its content.
{...} means: map or typed object, prefixed with its full class name, and its content.
