The Log.jsm
JavaScript code module (formerly named log4moz.js
) provides a log4j style API for logging log messages to various endpoints, such as the Browser Console or a file on disk. To use it, you first need to import the code module into your JavaScript scope:
Components.utils.import("resource://gre/modules/Log.jsm");
Basic usage
Components.utils.import("resource://gre/modules/Log.jsm"); // Get a logger, give it a name unique to this chunk of code. // Use dots to create a hierarchy, this way you can later change // the log level of sets of loggers under some common root let log = Log.repository.getLogger("MyExtension.MyClass"); log.level = Log.Level.Debug; // A console appender logs to the browser console. log.addAppender(new Log.ConsoleAppender(new Log.BasicFormatter())); // A dump appender logs to stdout. log.addAppender(new Log.DumpAppender(new Log.BasicFormatter())); // Log some messages log.error("Oh noes!! Something bad happened!"); log.debug("Details about bad thing only useful during debugging", {someInfo: "nothing"}); log.warn("Here is an error", new Error("ouch"));
Logger levels
FATAL | Severe errors that cause premature termination. Expect these to be immediately visible on a status console. |
ERROR | Other runtime errors or unexpected conditions. Expect these to be immediately visible on a status console. |
WARN | Use of deprecated APIs, poor use of API, 'almost' errors, other runtime situations that are undesirable or unexpected, but not necessarily "wrong". Expect these to be immediately visible on a status console. |
INFO | Interesting runtime events (startup/shutdown). Expect these to be immediately visible on a console, so be conservative and keep to a minimum. |
CONFIG | Information regarding important configuration options the system is using that affect how it runs. |
DEBUG | Detailed information on the flow through the system. Expect these to be written to logs only. |
TRACE | Most detailed information. Expect these to be written to logs only. |
Class overview
Appender(); |
length: 1 Keys of prototype :
|
|||||||
BasicFormatter(); |
length: 1 Keys of prototype :
|
|||||||
BoundedFileAppender(); |
length: 2 Keys of prototype :
|
|||||||
ConsoleAppender(); |
length: 1 Keys of prototype :
|
|||||||
DumpAppender(); |
length: 1 Keys of prototype :
|
|||||||
FileAppender(); |
length: 2 Keys of prototype :
|
|||||||
Formatter(); |
length: 0 Keys of prototype :
|
|||||||
LogMessage(); |
length: 4 Keys of prototype :
|
|||||||
Logger(); |
length: 2 Keys of prototype :
|
|||||||
LoggerRepository(); |
length: 0 Keys of prototype :
|
|||||||
StorageStreamAppender(); |
length: 1 Keys of prototype :
|
|||||||
StructuredFormatter(); |
length: 0 Keys of prototype :
|
Method overview
enumerateInterfaces(); |
length: 0 |
enumerateProperties(); |
length: 2 |
Member fields
Variable | Type | Description | ||||||||||||||||||||||
Level |
Object |
Contains the following fields:
|
||||||||||||||||||||||
repository |
LoggerRepository |
Logger methods
void fatal(string text, [optional] Object params); |
void error(string text, [optional] Object params); |
void warn(string text, [optional] Object params); |
void info(string text, [optional] Object params); |
void config(string text, [optional] Object params); |
void debug(string text, [optional] Object params); |
void trace(string text, [optional] Object params); |
Document Tags and Contributors
Tags:
Contributors to this page:
Mkmelin,
kscarfone,
gfritzsche,
Zorbing,
MattBrubeck,
mnoorenberghe,
unfocused
Last updated by:
Mkmelin,