Using Log4J with the Aion Java Interface Layer to Debug/Monitor Aion Java Sessions

Document ID : KB000028084
Last Modified Date : 14/02/2018
Show Technical Document Details

Log4J is the Apache Logging Services Project for Java. It can be used in conjunction with the CleverPath Aion Business Rules Expert ("Aion") Java Interface layer to monitor Aion Java session management. The Log4J functionality ("log4j-1.2.5.jar") is provided as part of Aion 9.5 and is available in the %Aion_HOME%\build\rejava folder on Windows and in the $Aion_HOME/build/rejava directory on UNIX.

The core functionality to manage Aion Java sessions is available in the "aionsession.jar" file (which is available at the same location as the Log4J jar file). Of the several classes available in aionsession.jar, the most useful logging detail could come from monitoring the AionSession object that encapsulates a session. Because the AionSession Java source is built with different levels of logging, you can configure Log4j (using a log4j.properties file) to output the required amount of logging detail. The decreasing order of logging detail level is: DEBUG, INFO, WARN, ERROR, FATAL.

For example, a simple log4j.properties file configured to give DEBUG level detail for AionSession objects is provided below:

# A simple log4j properties file

# Set the root logger level to warn and add some appenders
log4j.rootLogger=WARN, A1

# A1 is set to be a ConsoleAppender.
log4j.appender.A1=org.apache.log4j.ConsoleAppender

# A1 uses PatternLayout.
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n

log4j.logger.ca.aion.j2aion.AionSession=DEBUG, A2

# Appender A2 writes to the file "Mylog.txt".
log4j.appender.A2=org.apache.log4j.FileAppender
log4j.appender.A2.File=Mylog.txt

# Truncate 'Mylog.txt' if it already exists.
log4j.appender.A2.Append=false

# Appender A2 uses the PatternLayout.
log4j.appender.A2.layout=org.apache.log4j.PatternLayout
log4j.appender.A2.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n

(You can find more information and samples on how to use the Log4J package from the Apache Jakarta Project site: http://jakarta.apache.org)

This will log a lot of DEBUG-level detail into the file "Mylog.txt". To change the logging detail level from DEBUG to WARN (i.e., to only output any warning messages), simply change the following line:

log4j.logger.ca.aion.j2aion.AionSession=DEBUG, A2

to

log4j.logger.ca.aion.j2aion.AionSession=WARN, A2

If you want to output the logging detail for other classes, you can simply add another line for that class. For example, to monitor the AionObject instances for warning messages only, you can add:

log4j.logger.ca.aion.j2aion.AionObject=WARN, A2

Note that, in general, turning on DEBUG level for a class can output too much detail and may not be very useful, especially if a large number of objects of that class exist. For example, because there can be a lot of AionObject instances per AionSession, turning on DEBUG level for AionObject might not be very useful. In general, the most useful Aion Java session management class to monitor using Log4J is AionSession.

Finally, you can add your own Java classes to the log4j.properties file. Of course, that means your Java code should incorporate the logging statements. The following will turn on the INFO level logging detail for com.myclasses.TestAionJava.

log4j.logger.com.myclasses.TestAionJava =INFO, A2

Here is an example of part of a log generated by turning on DEBUG level detail for AionSession. It shows that new AionSession objects are created by different threads with sessionId?s 1, 2, 3, 4 etc and the last line shows that 1000 objects allocated in sessionId 1 are de-allocated (before that session is terminated).

2 [0] DEBUG ca.aion.j2aion.AionSession - factory create new aionSession Session: Thread[0,5,main], sessionId: 1, objectSize: 0
784 [1] DEBUG ca.aion.j2aion.AionSession - factory create new aionSession Session: Thread[1,5,main], sessionId: 2, objectSize: 0
1256 [2] DEBUG ca.aion.j2aion.AionSession - factory create new aionSession Session: Thread[2,5,main], sessionId: 3, objectSize: 0
1758 [3] DEBUG ca.aion.j2aion.AionSession - factory create new aionSession Session: Thread[3,5,main], sessionId: 4, objectSize: 0
...
...
7000 [0] DEBUG ca.aion.j2aion.AionSession - Aion memory allocation deleted successfully for Session: Thread[0,5,main], sessionId: 1, objectSize: 1000
...