In some circumstances, for example while jEdit is starting up, it may not practical to call GUIUtilities.message() and GUIUtilities.error() for every message and error that comes up. In those cases, you probably want to print the messages to some sort of log that the user can review later. While System.out.println() and friends may seem like an obvious choice for this task, it is not always the best, for the following reasons:
The user might not want to keep a system console window open to watch jEdit messages
People who use the console might get annoyed if you print too many messages
People trying to debug the plugin might find that it doesn't print enough information
There is no easy way to save a plugin's output (on Unix you can select output in an X terminal with the mouse and copy it, but this is not possible on Windows).
To overcome these problems, jEdit has its own logging API.
import org.gjt.sp.util.Log; |
public static void log
(int urgency, Object source, Object message);
This method appends a message to the activity log (see the section called The Activity Log in Chapter 3). urgency is one of Log.DEBUG, Log.MESSAGE, Log.NOTICE, Log.WARNING, or Log.ERROR. Messages with an urgency below Log.WARNING are only printed in the log; those with Log.WARNING or Log.ERROR urgency are also printed on the system console. The source parameter is used to label the logged message; it is either an object or a class. If source is null, the current thread's name is used. The message parameter is the message that is to be logged; it should either be a string or a java.lang.Throwable (the common superclass of all exceptions and errors). If you pass a Throwable, its stack trace is logged.
Assuming that the below example occurs in the implementation for the FooPlugin class, the text "[notice] FooPlugin: loading foo.dat..." will be appended to the activity log:
Log.log(Log.NOTICE,this,"loading foo.dat..."); |