//js增加打印日志的方法 var ac = Components.classes["@mozilla.org/steel/application;1"] .getService(Components.interfaces.steelIApplication).console; ac.log("====addressbook load begin===="); |
1. 创建一个共用的js文件,如thinkmaillog.js,把如下内容复制进来 var gThinkmailLog = null; function initThinkmailLog() { Components.utils.import("resource:///modules/gloda/log4moz.js"); // 这里的字符串标识随便指定 gThinkmailLog = Log4Moz.repository.getLogger("ThinkMailLog"); gThinkmailLog.level = Log4Moz.Level["All"]; // 在appdata下创建日志文件 var logFile = FileUtils.getFile("ProfD", ["thinkmaillog.txt"]); // 如果指定其他路径,可以这样创建一个文件对象 //var logFile = Components.classes["@mozilla.org/file/local;1"] // .createInstance(Components.interfaces.nsILocalFile); //logFile.initWithPath("D:\\mozlog.txt"); gThinkmailLog.addAppender(new Log4Moz.FileAppender(logFile, new Log4Moz.BasicFormatter())); } initThinkmailLog(); 2. 在其他需要的地方引入这个js,然后打印日志: gThinkmailLog.error("Something bad happened!"); gThinkmailLog.debug("Debug messages"); gThinkmailLog.info("Normal information"); 此外还支持 fatal, warn, config, trace,一共7种日志类型。 3. 查看日志文件,格式如下: 2014-07-14 18:18:21 ThinkMailLog ERROR Something bad happened! 2014-07-14 18:18:21 ThinkMailLog DEBUG Debug messages 2014-07-14 18:18:21 ThinkMailLog INFO Normal information Components.utils.import("resource:///modules/FileUtils.jsm"); |
https://wiki.mozilla.org/MailNews: Logging Please enable Thunderbird to write extra information to a log file, by setting two environment variables before running a MailNews application. Main module options within MailNews MailNews applications (SeaMonkey/Thunderbird) allow these modules/protocols in both debug and release builds: imap ImapAutoSync ldap mime msgdb (level 1=opens/closes, level 5 lists open db's on close, number of msg hdrs in use) MSGDB 对应 nsMsgDatabase.cpp nntp pop3 smtp IMPORT //通讯录导入 MimeHtmlEmitter nsMimeHtmlEmitter.cpp ParseMailbox nsParseMailbox.cpp nsRDFService nsRDFService.cpp HelperAppService nsExternalHelperAppService.cpp MsgBiff //检测服务端和客户端邮件的变化,以进行同步。MsgPurgeLogModule = PR_NewLogModule("MsgPurge"); //定期整理(压缩服务) bool DebugOut() { nsresult rv; nsCOMPtr<nsIPrefBranch> pref = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv); if (NS_FAILED(rv)) return false; bool bDebug = false; pref->GetBoolPref("debug.info.out", &bDebug); return bDebug; }
|
欢迎光临 firemail (http://firemail.wang:8088/) | Powered by Discuz! X3 |