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

FATALSevere errors that cause premature termination. Expect these to be immediately visible on a status console.
ERROROther runtime errors or unexpected conditions. Expect these to be immediately visible on a status console.
WARNUse 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.
INFOInteresting runtime events (startup/shutdown). Expect these to be immediately visible on a console, so be conservative and keep to a minimum.
CONFIGInformation regarding important configuration options the system is using that affect how it runs.
DEBUGDetailed information on the flow through the system. Expect these to be written to logs only.
TRACEMost detailed information. Expect these to be written to logs only.

Class overview

Appender();length: 1
Keys of prototype:
append();
doAppend();
level: 0
BasicFormatter();length: 1
Keys of prototype:
format();
BoundedFileAppender();length: 2
Keys of prototype:
doAppend();
reset();
ConsoleAppender();length: 1
Keys of prototype:
doAppend();
DumpAppender();length: 1
Keys of prototype:
doAppend();
FileAppender();length: 2
Keys of prototype:
doAppend();
reset();
Formatter();length: 0
Keys of prototype:
format();
LogMessage();length: 4
Keys of prototype:
levelDesc
Logger();length: 2
Keys of prototype:
addAppender();
level
logStructured();
name
parent
removeAppender();
updateAppenders();
And the methods mentioned below: Logger methods
LoggerRepository();length: 0
Keys of prototype:
getLogger();
rootLogger
StorageStreamAppender();length: 1
Keys of prototype:
doAppend();
getInputStream();
newOutputStream();
outputStream
reset();
StructuredFormatter();length: 0
Keys of prototype:
format();

Method overview

enumerateInterfaces();length: 0
enumerateProperties();length: 2

Member fields

VariableTypeDescription
LevelObjectContains the following fields:
Field NameValue
All0
Config30
Debug20
Desc{ 0: "ALL", 10: "TRACE", 20: "DEBUG", 30: "CONFIG", 40: "INFO", 50: "WARN", 60: "ERROR", 70: "FATAL" }
Error30
Fatal70
Info40
Numbers{ "ALL": 0, "TRACE": 10, "DEBUG": 20, "CONFIG": 30, "INFO": 40, "WARN": 50, "ERROR": 60, "FATAL": 70 }
Trace10
Warn50
repositoryLoggerRepository 

 

 

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:37 次

字数:11437

最后编辑:8年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文