JRun lets you customize and extend the logging configuration, as follows:
The file writer can write to multiple files, based on message level. This makes it easy to isolate messages by type. To enable multiple-file logging, add {log.level} to the FileLogEventHandler service's filename attribute, as the following example shows:
<service class="jrunx.logger.FileLogEventHandler" name="FileLogEventHandler">
<attribute name="filename">{jrun.rootdir}/logs/{jrun.server.name}-{log.level}-event.log</attribute>
<attribute name="rotationSize">200000</attribute>
<attribute name="rotationFiles">3</attribute>
<attribute name="heading"># Created by JRun on {date MM/dd HH:mm:ss}</attribute>
<attribute name="closeDelay">5000</attribute>
��<attribute name="deleteOnExit">false</attribute>
</service>
For example, when using level-specific log files, the default JRun server writes the following log files:
Directing log output to the screen can be useful during the development and testing phases of a project. In addition to viewing the JRun debug messages, you can add log methods to the code and view them in the console window in real time.
This section explains how to use the console log writer to direct log messages to a console window. It provides separate instructions for Windows and Unix.
To enable the console log writer, perform the following steps:
To use the console log writer, you must run JRun as a application. The console log writer does not work when running JRun as a Windows service.
ConsoleLogEventHandler service, located inside the ThreadedLogEventHandler service.
The console displays log entries.
To enable the console log writer, perform the following steps:
ConsoleLogEventHandler service, located inside the ThreadedLogEventHandler service.
The console displays log entries.
The JRun logging architecture lets you write customized log event handlers. For example, you might create a log event handler that writes messages in a site-specific format or to a database. You can also use this capability to write log messages using an alternative logging API, such as log4j or the JDK 1.4 java.util.logging package.
To create a customized log event handler, you must perform the following steps:
service element in the jrun.xml file.
The MBean interface, which is required as part of the JRun JMX-based architecture, defines methods that correlate to properties in the jrun.xml file. When you specify values for these properties in the jrun.xml file, JRun initializes these values automatically when the server starts. A log event handler MBean interface must extend the LogEventHandlerMBean interface and must also include the following:
import statement for jrunx.logger.*.
import statement for jrunx.kernal.*.The following code defines an MBean interface for the XML log event handler:
import jrunx.logger.*;
import jrunx.kernel.*;
/**
* MBean interface for the XML Log Event Handler
*
* @author Macromedia, Inc.
* @date 5December2001
*/
public interface XMLLogEventHandlerMBean
extends LogEventHandlerMBean {
/**
* Sets the name of the file to be used for XML logging
* @param filename The filename
*/
public void setFilename(String filename);
/**
* Gets the name of the file to be used for XML logging
* @return The filename
*/
public String getFilename();
}
A log event handler is a Java class that must include the following items:
import statement for jrunx.logger.* (to compile, you must add jrun_root/lib/jrun.jar to the classpath)
jrunx.logger.LogEventHandler and implements the MBean interfacelogEvent method, defined as follows:public synchronized boolean logEvent(LogEvent event)
JRun calls the logEvent method when a log request occurs. This method contains the majority of your logging logic.
init, start, stop, and destroy methods, which perform lifecycle-specific processingJRun calls log event handler methods in the following order:
set methods, using attributes defined in jrun.xml
initstartlogEvent, which is called repeatedly while JRun is runningstopdestroyThe following code defines a log event handler that writes log messages in a simple XML-like format:
import java.io.*;
import java.util.*;
import java.text.*;
import jrunx.logger.*;
/**
* Log events in XML format to a file
* This extends LogEventHandler, which requires that this
* class implement the logEvent method.
* It implements XMLLogEventHandlerMBean, which defines the
* getFilename and setFilename methods.
*/
public class XMLLogEventHandler extends LogEventHandler
implements XMLLogEventHandlerMBean {
protected String filename;
protected SimpleDateFormat dateFormat = new SimpleDateFormat("MM/HH hh:mm:ss");
protected String defaultFormat = null;
// JRun initializes the writer at server startup
public void init(Properties props) {
dateFormat = new SimpleDateFormat("MM/HH hh:mm:ss");
}
/**
* Sets the name of the file to be used for XML logging.
* @param filename The filename
*/
public void setFilename(String filename) {
if (filename == null) {
this.filename = "xml.log";
}
else {
this.filename = filename;
}
}
/**
* Gets the name of the file to be used for XML logging
* @return The filename
*/
public String getFilename() {
return filename;
}
// JRun calls the logEvent method when a log action is requested.
public synchronized boolean logEvent(LogEvent event) {
PrintWriter out = null;
try {
FileOutputStream fos = new FileOutputStream(filename, true);
out = new PrintWriter(fos, true);
// Get the pieces and parts.
Properties p = event.getVariables(defaultFormat);
String level = (String)p.get("log.level");
String msg = (String)p.get("log.message");
String exception = (String)p.get("log.exception");
Date date = new Date();
String formattedDate;
synchronized(dateFormat) {
formattedDate = dateFormat.format(date);
}
// Crude format.
out.println("<log>");
out.println(" <time>" + date + "</time>");
out.println(" <level>" + level + "</level>");
out.println(" <message>" + msg + "</message>");
out.println(" <exception>" + exception + "</exception>");
out.println("</log>");
}
catch (Exception ex) {
ex.printStackTrace();
}
finally {
if (out != null) {
out.close();
} // end if
} // end finally
return true;
} // end logEvent method
public void flush()
{
// No-op
}
}
You define the XMLLogEventHandler as a service within ThreadedLogEventHandler service in the jrun.xml file. The service contains a filename attribute, as the following example shows:
...
<service class="jrunx.logger.ThreadedLogEventHandler" name="ThreadedLogEventHandler">
<service class="jrunx.logger.FileLogEventHandler" name="FileLogEventHandler">
<attribute name="filename">{jrun.rootdir}/logs/{jrun.server.name}-event.log</attribute>
<attribute name="rotationSize">200000</attribute>
<attribute name="rotationFiles">3</attribute>
<attribute name="heading"># Created by JRun on {date MM/dd HH:mm:ss}</attribute>
<attribute name="closeDelay">5000</attribute>
</service>
<service class="XMLLogEventHandler" name="XMLLogEventHandler">
<attribute name="filename">{jrun.rootdir}/logs/{jrun.server.name}-event.xml
</attribute>
</service>
</service>
...
RSS feed | Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/jrun/4/JRun_Administrators_Guide/logging4.htm
Comments
jrunrandy said on Aug 1, 2003 at 1:34 PM : urmila said on Sep 18, 2003 at 11:42 AM : Techek said on Nov 26, 2003 at 1:23 PM :