![]() |
|||
| Contents | / Index | / Glossary | / Administration Tool Help |
There are many compelling reasons to modify log formats. Fortunately, the Java Web Server(TM) was designed in such a way that this customization is possible. However, customizing log formats produced by the server is not a supported action--here's why.
The procedure for modifying server logs:
However, because so many people have asked to have more control over how log files work, we've written these cookbook-style instructions. We hope you will find them helpful should you ever need to customize log output in the Java Web Server.
Each of these steps is explained in more detail below. An example illustrating the procedure is also provided at the end of this document.
| Type | Filename | Information recorded | Default |
|---|---|---|---|
| Access | access_log | For every access to server resources, the details. | on |
| Agent | agent_log | For every http request, contains the datestamp and the contents of the User-Agent header. | off |
| Combined | combined_log | Same as access log, but with agent, referer, and server information added. | off |
| Error | error_log | For selected server errors, contains the datestamp and a stack dump. | off |
| Event | event_log | For selected server events, contains the datestamp and a message. | off |
| Referer | referer_log | For every http request, contains the datestamp and the contents of the Referer header. | off |
formatclass,
and is found in the system properties in a format like this:
log.logname.formatclass=classnamewhere logname is the internal name of the log concerned, and classname is the fully-qualified packagename of the class.
As an example of this in use, the default formatclass for access logs is:
log.access.formatclass=com.sun.server.log.http.HttpLogwhile the default formatclass for error logs is:
log.error.formatclass=com.sun.server.log.TraceLog
To write the formatclass, you need to subclass the base class that the log expects, and override the implementation of write() that that class supports. Here's a table of information you need to know:
| Log Name | Class to extend | method to override |
|---|---|---|
| access | com.sun.server.log.http.HttpLog | write(sun.servlet.http.ServletRequest req, sun.servlet.http.ServletResponse res) |
| agent | com.sun.server.webserver.AgentLog | write(sun.servlet.http.ServletRequest req, sun.servlet.http.ServletResponse res) |
| combined | ||
| error | com.sun.server.log.TraceLog | write(String message) or write(int level, String message) |
| event | com.sun.server.log.TraceLog | write(String message) or write(int level, String message) |
| referer | com.sun.server.webserver.RefererLog | write(sun.servlet.http.ServletRequest req, sun.servlet.http.ServletResponse res) |
import sun.servlet.http.*;
public class MyAgentLog extends com.sun.server.webserver.AgentLog {
public MyAgentLog() {
super();
}
public AgentLog(OutputStream out) {
super(out);
}
public void write(HttpRequest req, HttpResponse) {
if (getLevel() > 0) {
synchronized (this) {
try {
print(req.getRequestURI());
print(" ");
req.getHeader("User-Agent");
println(req.getHeader("User-Agent"));
} catch (IOException e) {
System.err.println("AgentLog.write() : " + e);
}
}
}
}
}
server_root/properties/javawebserver/systemDefaults.propertieswhere server_root is the full path to where the Java Web Server is installed.
In the file, we would change the line
log.agent.formatclass=com.sun.server.webserver.AgentLog
to read
log.agent.formatclass=myAgentLog
Note: The agent log for the Java Web Server's webpage service will be created as:
server_root/logs/javawebserver/webpageservice/agent_logwhere server_root is the full path to where the Java Web Server is installed.
Top
java-server-feedback@java.sun.com
|
Copyright © 1999
Sun Microsystems, Inc. All Rights Reserved. |