Removed log message caching from the default log provider in the interest
of KISS. Someday the default log provider will surely be able to read e-mail, otherwise it will be replaced by someone else's log provider that can. git-svn-id: https://samskivert.googlecode.com/svn/trunk@871 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: DefaultLogProvider.java,v 1.16 2002/10/16 19:10:13 shaper Exp $
|
// $Id: DefaultLogProvider.java,v 1.17 2002/10/16 19:30:15 shaper Exp $
|
||||||
//
|
//
|
||||||
// samskivert library - useful routines for java programs
|
// samskivert library - useful routines for java programs
|
||||||
// Copyright (C) 2001 Michael Bayne
|
// Copyright (C) 2001 Michael Bayne
|
||||||
@@ -22,8 +22,6 @@ package com.samskivert.util;
|
|||||||
|
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
|
|
||||||
import java.io.PrintStream;
|
|
||||||
|
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -31,8 +29,6 @@ import java.util.Date;
|
|||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.samskivert.io.ExtensiblePrintStream;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If no log provider is registered with the log services, the default
|
* If no log provider is registered with the log services, the default
|
||||||
* provider will be used. The default provider simply logs messages to
|
* provider will be used. The default provider simply logs messages to
|
||||||
@@ -63,45 +59,6 @@ public class DefaultLogProvider implements LogProvider
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets whether recent log messages should be cached and made
|
|
||||||
* available via {@link #getRecentMessages}. The default setting is
|
|
||||||
* <code>false</code>. Note that currently all messages logged after
|
|
||||||
* caching is turned on will be kept forever (or until caching is
|
|
||||||
* turned off.)
|
|
||||||
*/
|
|
||||||
public synchronized void setCacheMessages (boolean cache)
|
|
||||||
{
|
|
||||||
if (cache && _recent == null) {
|
|
||||||
// create the list of recent messages
|
|
||||||
_recent = new ArrayList();
|
|
||||||
|
|
||||||
// swap in our own custom output streams for stdout and stderr
|
|
||||||
// in order to cache all future output
|
|
||||||
_oout = System.out;
|
|
||||||
_oerr = System.err;
|
|
||||||
System.setOut(new CachingPrintStream(_oout));
|
|
||||||
System.setErr(new CachingPrintStream(_oerr));
|
|
||||||
|
|
||||||
} else if (!cache && _recent != null) {
|
|
||||||
// clear out the recent message list
|
|
||||||
_recent = null;
|
|
||||||
|
|
||||||
// restore the original output streams
|
|
||||||
System.setOut(_oout);
|
|
||||||
System.setErr(_oerr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a list of the recent log messages, or <code>null</code> if
|
|
||||||
* log messages are not currently being cached.
|
|
||||||
*/
|
|
||||||
public synchronized List getRecentMessages ()
|
|
||||||
{
|
|
||||||
return _recent;
|
|
||||||
}
|
|
||||||
|
|
||||||
public synchronized void log (
|
public synchronized void log (
|
||||||
int level, String moduleName, String message)
|
int level, String moduleName, String message)
|
||||||
{
|
{
|
||||||
@@ -216,40 +173,6 @@ public class DefaultLogProvider implements LogProvider
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* A print stream that caches all printed text in the {@link #_recent}
|
|
||||||
* list.
|
|
||||||
*/
|
|
||||||
protected class CachingPrintStream extends ExtensiblePrintStream
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Constructs a caching print stream that caches all output
|
|
||||||
* written to the supplied stream.
|
|
||||||
*/
|
|
||||||
public CachingPrintStream (PrintStream s)
|
|
||||||
{
|
|
||||||
super(s, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
// documentation inherited
|
|
||||||
public void handlePrinted (String s)
|
|
||||||
{
|
|
||||||
_buf.append(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
// documentation inherited
|
|
||||||
public void handleNewLine ()
|
|
||||||
{
|
|
||||||
// save off the text
|
|
||||||
_recent.add(_buf.toString());
|
|
||||||
// clear out the line buffer
|
|
||||||
_buf = new StringBuffer();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The working string that gathers each log message line. */
|
|
||||||
protected StringBuffer _buf = new StringBuffer();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Whether or not to use the vt100 escape codes. */
|
/** Whether or not to use the vt100 escape codes. */
|
||||||
protected boolean _useVT100 = false;
|
protected boolean _useVT100 = false;
|
||||||
|
|
||||||
@@ -263,15 +186,6 @@ public class DefaultLogProvider implements LogProvider
|
|||||||
protected SimpleDateFormat _format =
|
protected SimpleDateFormat _format =
|
||||||
new SimpleDateFormat("yyyy/MM/dd HH:mm:ss:SSS");
|
new SimpleDateFormat("yyyy/MM/dd HH:mm:ss:SSS");
|
||||||
|
|
||||||
/** The cached recent log messages that are made available to any
|
|
||||||
* external entities that would like access to them if we're actually
|
|
||||||
* caching messages. */
|
|
||||||
protected ArrayList _recent;
|
|
||||||
|
|
||||||
/** The original output streams that we save off if we're caching
|
|
||||||
* recent log messages. */
|
|
||||||
protected PrintStream _oout, _oerr;
|
|
||||||
|
|
||||||
/** Contains the dimensions of the terminal window in which we're
|
/** Contains the dimensions of the terminal window in which we're
|
||||||
* running, if it was possible to obtain them. Otherwise, it contains
|
* running, if it was possible to obtain them. Otherwise, it contains
|
||||||
* the default dimensions. This is used to wrap lines. */
|
* the default dimensions. This is used to wrap lines. */
|
||||||
|
|||||||
Reference in New Issue
Block a user