Expresso LoggingOne of the main advantages of linux and other multi user systems is the
logging ability. Expresso integrates with Logging standards to create logs,
thereby documenting and storing certain system or user activity. This document
seeks to describe the logging mechanism used within Expresso. It will cover
basic requirements, rationale behind various decisions and a detailed walkthrough
of the various logging categories and the purpose of each category.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Version: |
Expresso 5.0 |
Author: |
Michael Rimov and other Contributors |
One of the main advantages of linux and other multi user systems is the
logging ability. What is logging exactly? It is merely a process of creating
logs, documenting and storing certain system or user activity for various
reasons. Entire process and idea of logging probably came from programming,
where it was useful to record events, such as program behaviour for further
development, and to collect such information for future diagnostic and
improvement. Same is with logging on the system level. It is, to say the
least, useful to log all activities and events that took place on your
system for future analysis. From a security point of view, logging serves
as a proof of malicious activity or as an indicator of a potential one.
Any framework needs logging facilities to assist in the development of applications on top of the framework. The basic requirements of this logging facility is outlined below:
Expresso is integrated with the Apache Log4j API. Log4j is an open source project based on the work of many authors. It allows the developer to control which log statements are output with arbitrary granularity. It is fully configurable at runtime using external configuration files. Best of all, log4j has a gentle learning curve.
To achieve these requirements. We have selected the logging system log4j for the following reasons:
The LogManager class is Expresso's interface to the Apache Log4j framework,
and is used to set up logging for all applications in a particular environment.
When ConfigManager first calls LogManager during system startup, all files
with names of the form "*Logging.xml" in the configuration directory
are read, and logging channels are then available for each of the channels
defined in these files. This allows each application to have it's own seperate
logging configuration file, e.g. expressoLogging.xml for Expresso's own
internal classes, eForumLogging.xml for eForum, and so forth.
The primary means for monitoring the intranet system is via a log.
All activities run and monitored by Expresso are logged into an HTML server
log, accessible via any web browser. This allows the server to be monitored
remotely as required, for completely remote system administration and operation.
Most tasks are triggered by the application framework, and it writes status
notifications, warnings and error messages to the log. Multiple logs can
be set up for separate facilities, or one master log can be used for centralized
collection of log data. For more information please refer to the Log4j project and the Log4j manual.
To have Log4J fit into Expresso with the best capabilities, there will have to be some additions made other than simply using the straight logging code:
All logging operations will be encapsulated within the com.jcorporate.expresso.core.logging package. It needs to be located there instead of within the services subtree because the logging code will be integrated throughout the entire framework and will not be easily separated out. Package organization will be:
com.jcorporate.expresso.core.logging will contain the
global debug switch file, the logging configuration properties file, the static
initializer for the logging system, and any othe miscellaneous files that would
not fit any of the other subpackages.com.jcorporate.expresso.core.logging.appenders will
initially contain the DBAppender as well as any other appenders that may be
added at a later time. Examples include an HtmlCommentAppender to dump logs into
the servlet output stream, and JMSAppender to dump log activity into a Java
Message Queue.Log4j supports both properties files and XML configuration files. Due to the potentially complex configuration options of the categories, it is recommended that an XML configuration file be used.
The second configuration mechanism will be the class
com.jcorporate.expresso.core.logging.debugLogging which will
contain the public static final boolean member variable "debug" Which will be
used to turn on/off any references to debug logging. The ExpressoLog class will
also contain the factory method to initialize logging throughout the framework
at startup time.
Finally, the expresso config file will need to point to a directory where events will be logged to.
DBAppender - This class will provide the functionality to log system events to the database table syslog. It will take care of the appropriate color coding necessary, and will seek to provide the same functionality that currently exists in Expresso Logging.
HTMLCommentAppender - This class will allow for embedding log statements as comments within an html page returned by a servlet. This will assist in rapid debugging and is easily turned off for a secure production envrionment.
SessionAppender - This appender will store the log information into the session. The servlets can have a javascript window open up which calls a servlet that will dump the session log into a web page.
JMSAppender - Expresso J2EE Only This will give the ability of logging to be dumped to a Message Queue Server. This gives the framework secure remote monitoring ability as the JMS messages will be distributed over SSL instead of in the clear. It is recommended that this appender be donated to the log4j initiative to provide better debugging / iterations as time goes on, and this appender is listed in the "TODO" list for upcoming features of log4j anyway.
This section details the appenders that have been set up in the default configuraiton file. If you wish to change how a category is logged, please check here for names of the default appenders.
| Designation |
Description
|
Appender Type | Logging Pattern |
expressoLog |
The log file that expresso uses to commit any special warnings/errors that would not normally be able to be sent to the database. The expressoLog filename/location is set in the Expresso Configuration file with the entry logFile=<PATH/TO/LOGFILE> |
FileAppender | |
console |
Prints the log message directly to System.out | FileAppender | |
stderr |
Logs the message to System.err() | FileAppender | |
dbLog |
Logs all messages to the database | DBAppender | |
httpSessionLog |
Logs all the messages to the current session for retrieval. Through a snooping servlet | SessionAppender |
This section is by far the most detailed portion of this document. Categories set up in a tree-like fashion. The overall goal is to provide good grouping by functionality as well as class hierarchy. For each category listed, there will be the following information provided:
Note, the chosen appenders and priorities are only defaults. They may be changed at any time by the configuration file.
| Designation | Parent |
Description
|
Default Appenders | Priority |
expresso |
<root> | The base category for all log messages from the framework and any other derived works. | expressoLog | Error |
expresso.core |
expresso | The base category for dealing with events/ logging in Expresso's core services | expressoLog | warn |
expresso.services |
expresso | The base category for dealing with events/ logging in Expresso's added services | FileAppender | Error |
expresso.core. |
expresso.core | The base category for all security related messages such as failed login attempts, failed ACL requests, failed JVM security context errors, as well as other security checks. | expressoLog dbLog |
Info |
expresso.core. |
expresso.core.security | This category is active for all logged in supervisors. All actions that the supervisor performs are then traced. Examples include login, event-clearing, addition of users, etc. All servlets should report the actions taken by an Administrative session. | expressoLog dbLog console |
Info |
| expresso.core.db | expresso.core | The base category for all db log messages from the framework. | expressoLog | Warn |
expresso.db.SQL |
expresso.core.db | The category for tracing all SQL calls made to underlying database objects. | expressoLog | Error |
expresso.core. |
expresso.core | The base category for any caching messages, tracing | expressoLog | Warn |
expresso.core. |
expresso.core | Tracking all servlet-api calls | dbLog console |
Warn |
expresso.core. |
expresso.core | For tracking all job related information | dbLog | Warn |
expresso.core. |
expresso.core | The base category for any servlet-related logging messages. Individual servlets should create their own logging categories as a subcategory of expresso.servlet | dbLog | Warn |
expresso.core. |
expresso.core.servlet | The category for tracking state listing and changes within the controller package. | dbLog | Warn |
expresso.services. |
expresso.services | Category for tracking all uses of DBTool | expressoLog | Info |
expresso.services. |
expresso.services | The base category for any servlet-related logging messages. Individual servlets should create their own logging categories as a subcategory of expresso.servlet. This covers all servlets that are not part of the Expresso core. | dbLog | Warn |
expresso.services. |
expresso.services.servlet | For Tracking all uses of DBMaint | dbLog | Warn |
Editorial note for furture revision :TODO: categorize the following logging mechanisms: Startup Logging, Other System Events. Specify the format specifiers for each category.
The full log4j documentation may be found here. At first, the number of possibilities for log4j may seem bewildering. However, to use it within your own work with Expresso is quite simple. Here's an example code snippit within your class:
|
import org.apache.log4j.Category ...
...
|
You can easily add logging to your own application. To do this, you:
We recommend that you study the Log4J manual included with the expresso distribution for a full feeling of the power of this logging framework. You can find it here.
Logging can be a serious performance drain if it is set up incorrectly - so it is important to have logging configured for your production environment for performance.
<param name="ConversionPattern" value="%d %-5p [%t] -
%m\n"/>
We remove all debug information from the logging event. For example, stack
traces will not be shown, nor will calling file location be displayed. This
greatly improves the efficiency of the logging event.
Database logging can be expensive on the target database. It is better to log to a file at a specified location rather than to a database server. Since dbLog is the only appender using the database. Change that value and all categories using that appender will now log to a file instead of the database.
<appender name="dbLog"
class="org.apache.log4j.RollingFileAppender">
<layout
class="org.apache.log4j.PatternLayout">
<param
name="ConversionPattern" value="[%t] -
%m"/>
</layout>
</appender>
Note also that this example uses the RollingFileAppender - This allows
the log to get rolled over whenever it reaches 10 Mb in size. Perfect for a long
term production environment. Other options to investigate are:
SyslogAppender, DailyRollingFileAppender, and NTEventLogAppender. Check the
log4j javadocs for more information on these classes.
Move category priorities to warn or error only.
By setting the categories to log log.error() and maybe log.warn() you effectively eliminate all the overhead of logging various categories unless something serious happens. Here's an example:
<category name="expresso.core" additivity="false"> <priority value="error"/> <appender-ref ref="expressoLog"/> </category>
This sets all expresso.core and subcategories to only log on Errors. Note that any hierachies that have additivity="false" must also be set because their parent categories have no effect on them.
For technical information about how to use logging, please refer to the:
|
Home | Products | Services | Partners | Customers | About Us | Login | Forums | Contact Us |
Copyright © 2001-2002 Jcorporate Ltd. All rights reserved. Copyright Privacy
Last Modified: 07-Oct-02 9:54:08 PM