public class Log
extends java.lang.Object
System.out.println()
and
full-blown logging packages such as log4j.All events are logged to an in-memory buffer and optionally a stream, and those with a high urgency (warnings and errors) are also printed to standard output.
Logging of exception tracebacks is supported.
This class can also optionally redirect standard output and error
to the log, see init(boolean, int)
.
Modifier and Type | Field and Description |
---|---|
static int |
DEBUG
Debugging message urgency.
|
static int |
ERROR
Error urgency.
|
static int |
MAXLINES
The maximum number of log messages that will be kept in memory.
|
static int |
MESSAGE
Message urgency.
|
static int |
NOTICE
Notice urgency.
|
static java.util.List<java.lang.Throwable> |
throwables |
static int |
WARNING
Warning urgency.
|
Constructor and Description |
---|
Log() |
Modifier and Type | Method and Description |
---|---|
static void |
closeStream()
Closes the log stream.
|
static void |
flushStream()
Flushes the log stream.
|
static boolean |
getBeepOnOutput() |
static javax.swing.ListModel<java.lang.String> |
getLogListModel()
Returns the list model for viewing the log contents.
|
static void |
init(boolean stdio,
int level)
Initializes the log.
|
static void |
log(int urgency,
java.lang.Object source,
java.lang.Object message)
Logs a message.
|
static void |
log(int urgency,
java.lang.Object source,
java.lang.Object message,
java.lang.Throwable exception)
Logs an exception with a message.
|
static void |
setBeepOnOutput(boolean beepOnOutput)
When
beepOnOutput is set, every output going to standard
error is signaled by a standard beep. |
static void |
setLogWriter(java.io.Writer stream)
Writes all currently logged messages to this stream if there was no
stream set previously, and sets the stream to write future log
messages to.
|
public static int MAXLINES
public static final int DEBUG
public static final int MESSAGE
public static final int NOTICE
public static final int WARNING
public static final int ERROR
public static final java.util.List<java.lang.Throwable> throwables
public static void init(boolean stdio, int level)
stdio
- If true, standard output and error will be
intercepted and sent to the log. The urgency
for these implicit log entries is NOTICE
and ERROR
accordingly. Note that in such a situation
System.out.print()
calls will not appear on standard
output, if default output level is higher than NOTICE
.level
- Messages with this log level or higher will
be printed to the system console.public static void setLogWriter(java.io.Writer stream)
stream
- The writerpublic static boolean getBeepOnOutput()
public static void setBeepOnOutput(boolean beepOnOutput)
beepOnOutput
is set, every output going to standard
error is signaled by a standard beep. This is intended for debugging
purposes, to allow for immediate problem detection.public static void flushStream()
public static void closeStream()
public static javax.swing.ListModel<java.lang.String> getLogListModel()
public static void log(int urgency, java.lang.Object source, java.lang.Object message, java.lang.Throwable exception)
log
, then
the exception should be explicitly provided so that it can
be presented to the (debugging) user in a useful manner
(not just the exception message, but also the exception stack trace)public static void log(int urgency, java.lang.Object source, java.lang.Object message)
The following code sends a typical debugging message to the activity log:
Log.log(Log.DEBUG,this,"counter = " + counter);The corresponding activity log entry might read as follows:
[debug] JavaParser: counter = 15
urgency
- The urgency; can be one of
Log.DEBUG
, Log.MESSAGE
,
Log.NOTICE
, Log.WARNING
, or
Log.ERROR
.source
- The source of the message, either an object or a
class instance. When writing log messages from macros, set
this parameter to BeanShell.class
to make macro
errors easier to spot in the activity log.message
- The message. This can either be a string or
an exception