Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## net.sourceforge.jsxe.util
Class Log

    java.lang.Object
      net.sourceforge.jsxe.util.Log

public class Log
extends Object

This class provides methods for logging events. In terms of functionality, it is somewhere in between `System.out.println()` and full-blown logging packages such as log4j.

All events are logged to a Swing text document and optionally a stream, and those with a high urgency (warnings and errors) are also printed to standard output.

This class can also optionally redirect standard output and error to the log.

Since:
  jsXe 0.4 beta
Version:
  $Id: Log.java 994 2006-07-07 03:46:17Z ian_lewis $
Author:
  Slava Pestov, Ian Lewis (IanLewis@member.fsf.org)

Field Summary
`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 int` | `WARNING` Warning urgency.

Method Summary
`static void` | `closeStream()` Closes the log stream.
`static void` | `flushStream()` Flushes the log stream.
`static Document` | `getLogDocument()` Returns the document where the most recent messages are stored.
`static void` | `init(boolean stdio, int level, boolean debug)` Initializes the log.
`static void` | `log(int urgency, Object source, Object message)` Logs a message.
`static void` | `setDebug(boolean debug)` Sets whether debug is recorded to the log.
`static void` | `setLogWriter(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.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### MAXLINES

    public static final int MAXLINES

  The maximum number of log messages that will be kept in memory.

  See Also:
    Constant Field Values

### DEBUG

    public static final int DEBUG

  Debugging message urgency. Should be used for messages only useful when debugging a problem.

  See Also:
    Constant Field Values

### MESSAGE

    public static final int MESSAGE

  Message urgency. Should be used for messages which give more detail than notices.

  See Also:
    Constant Field Values

### NOTICE

    public static final int NOTICE

  Notice urgency. Should be used for messages that directly affect the user.

  See Also:
    Constant Field Values

### WARNING

    public static final int WARNING

  Warning urgency. Should be used for messages that warrant attention.

  See Also:
    Constant Field Values

### ERROR

    public static final int ERROR

  Error urgency. Should be used for messages that signal a failure.

  See Also:
    Constant Field Values

Method Detail

### init

    public static void init(boolean stdio,
                            int level,
                            boolean debug)

  Initializes the log.

  Parameters:
    `stdio` - If true, standard output and error will be sent to the log
    `level` - Messages with this log level or higher will be printed to the system console
    `debug` - If true, debug will be printed to the log even if it is not at or higher than the level (second arg)

### setLogWriter

    public static void setLogWriter(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.

  Parameters:
    `stream` - The writer

### getLogDocument

    public static Document getLogDocument()

  Returns the document where the most recent messages are stored. The document of a Swing text area can be set to this to graphically view log messages.

### flushStream

    public static void flushStream()

  Flushes the log stream.

### closeStream

    public static void closeStream()

  Closes the log stream. Should be done before your program exits.

### log

    public static void log(int urgency,
                           Object source,
                           Object message)

  Logs a message. This method is thread-safe.

  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

  Parameters:
    `urgency` - The urgency; can be one of `DEBUG`, `MESSAGE`, `NOTICE`, `WARNING`, or `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

### setDebug

    public static void setDebug(boolean debug)

  Sets whether debug is recorded to the log.

  Parameters:
    `debug` - If true, debug will be printed to the log even if it is not at or higher than the level.

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD