Log.jsm 编辑
This module is still under development.
Until stabilized, expect frequent updates, including different interfaces and behavior in different versions of the platform.
Progress is tracked in Bugzilla using dependencies of bug 451283.
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); |
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论