Fields Summary |
---|
private String | dateThe as-of date for the currently open log file, or a zero-length
string if there is no open log file. |
private String | directoryThe directory in which log files are created. |
protected static final String | infoThe descriptive information about this implementation. |
private String | prefixThe prefix that is added to log file filenames. |
private org.apache.catalina.util.StringManager | smThe string manager for this package. |
private boolean | startedHas this component been started? |
private String | suffixThe suffix that is added to log file filenames. |
private boolean | timestampShould logged messages be date/time stamped? |
private PrintWriter | writerThe PrintWriter to which we are currently logging, if any. |
Methods Summary |
---|
private void | close()Close the currently open log file (if any)
if (writer == null)
return;
writer.flush();
writer.close();
writer = null;
date = "";
|
public java.lang.String | getDirectory()Return the directory in which we create log files.
// ------------------------------------------------------------- Properties
return (directory);
|
public java.lang.String | getPrefix()Return the log file prefix.
return (prefix);
|
public java.lang.String | getSuffix()Return the log file suffix.
return (suffix);
|
public boolean | getTimestamp()Return the timestamp flag.
return (timestamp);
|
public void | log(java.lang.String msg)Writes the specified message to a servlet log file, usually an event
log. The name and type of the servlet log is specific to the
servlet container.
// Construct the timestamp we will use, if requested
Timestamp ts = new Timestamp(System.currentTimeMillis());
String tsString = ts.toString().substring(0, 19);
String tsDate = tsString.substring(0, 10);
// If the date has changed, switch log files
if (!date.equals(tsDate)) {
synchronized (this) {
if (!date.equals(tsDate)) {
close();
date = tsDate;
open();
}
}
}
// Log this message, timestamped if necessary
if (writer != null) {
if (timestamp) {
writer.println(tsString + " " + msg);
} else {
writer.println(msg);
}
}
|
private void | open()Open the new log file for the date specified by date .
// Create the directory if necessary
File dir = new File(directory);
if (!dir.isAbsolute())
dir = new File(System.getProperty("catalina.base"), directory);
dir.mkdirs();
// Open the current log file
try {
String pathname = dir.getAbsolutePath() + File.separator +
prefix + date + suffix;
writer = new PrintWriter(new FileWriter(pathname, true), true);
} catch (IOException e) {
writer = null;
}
|
public void | setDirectory(java.lang.String directory)Set the directory in which we create log files.
String oldDirectory = this.directory;
this.directory = directory;
support.firePropertyChange("directory", oldDirectory, this.directory);
|
public void | setPrefix(java.lang.String prefix)Set the log file prefix.
String oldPrefix = this.prefix;
this.prefix = prefix;
support.firePropertyChange("prefix", oldPrefix, this.prefix);
|
public void | setSuffix(java.lang.String suffix)Set the log file suffix.
String oldSuffix = this.suffix;
this.suffix = suffix;
support.firePropertyChange("suffix", oldSuffix, this.suffix);
|
public void | setTimestamp(boolean timestamp)Set the timestamp flag.
boolean oldTimestamp = this.timestamp;
this.timestamp = timestamp;
support.firePropertyChange("timestamp", Boolean.valueOf(oldTimestamp),
Boolean.valueOf(this.timestamp));
|
public void | start()Prepare for the beginning of active use of the public methods of this
component. This method should be called after configure() ,
and before any of the public methods of the component are utilized.
// Validate and update our current component state
if (started)
throw new LifecycleException
(sm.getString("fileLogger.alreadyStarted"));
lifecycle.fireLifecycleEvent(START_EVENT, null);
started = true;
super.start();
|
public void | stop()Gracefully terminate the active use of the public methods of this
component. This method should be the last one called on a given
instance of this component.
// Validate and update our current component state
if (!started)
throw new LifecycleException
(sm.getString("fileLogger.notStarted"));
lifecycle.fireLifecycleEvent(STOP_EVENT, null);
started = false;
close();
super.stop();
|