diff --git a/services/sync/BookmarksSyncService.js b/services/sync/BookmarksSyncService.js index 7f7c54014720..f25959c6637e 100644 --- a/services/sync/BookmarksSyncService.js +++ b/services/sync/BookmarksSyncService.js @@ -115,14 +115,6 @@ BookmarksSyncService.prototype = { return this.__os; }, - __console: null, - get _console() { - if (!this.__console) - this.__console = Cc["@mozilla.org/consoleservice;1"] - .getService(Ci.nsIConsoleService); - return this.__console; - }, - __dirSvc: null, get _dirSvc() { if (!this.__dirSvc) @@ -171,7 +163,7 @@ BookmarksSyncService.prototype = { serverURL = branch.getCharPref("browser.places.sync.serverURL"); } catch (ex) { /* use defaults */ } - this._log.config("Bookmarks login server: " + serverURL); + this._log.info("Bookmarks login server: " + serverURL); this._dav = new DAVCollection(serverURL); this._readSnapshot(); }, @@ -187,11 +179,11 @@ BookmarksSyncService.prototype = { root.level = root.LEVEL_ALL; let capp = logSvc.newAppender("console", formatter); - capp.level = root.LEVEL_INFO; + capp.level = root.LEVEL_WARN; root.addAppender(capp); let dapp = logSvc.newAppender("dump", formatter); - dapp.level = root.LEVEL_INFO; + dapp.level = root.LEVEL_WARN; root.addAppender(dapp); let dirSvc = Cc["@mozilla.org/file/directory_service;1"]. @@ -204,11 +196,12 @@ BookmarksSyncService.prototype = { verboseFile.QueryInterface(Ci.nsILocalFile); let fapp = logSvc.newFileAppender("rotating", logFile, formatter); - fapp.level = root.LEVEL_CONFIG; + fapp.level = root.LEVEL_INFO; root.addAppender(fapp); let vapp = logSvc.newFileAppender("rotating", verboseFile, formatter); vapp.level = root.LEVEL_ALL; root.addAppender(vapp); + this._log.info("WHEE"); }, _saveSnapshot: function BSS__saveSnapshot() { @@ -570,7 +563,7 @@ BookmarksSyncService.prototype = { _applyCommandsToObj: function BSS__applyCommandsToObj(commands, obj) { for (let i = 0; i < commands.length; i++) { - this._log.info("Applying cmd to obj: " + uneval(commands[i])); + this._log.debug("Applying cmd to obj: " + uneval(commands[i])); switch (commands[i].action) { case "create": obj[commands[i].GUID] = eval(uneval(commands[i].data)); @@ -592,7 +585,7 @@ BookmarksSyncService.prototype = { _applyCommands: function BSS__applyCommands(commandList) { for (var i = 0; i < commandList.length; i++) { var command = commandList[i]; - this._log.info("Processing command: " + uneval(command)); + this._log.debug("Processing command: " + uneval(command)); switch (command["action"]) { case "create": this._createCommand(command); @@ -619,11 +612,10 @@ BookmarksSyncService.prototype = { parentId = this._bms.bookmarksRoot; } - this._log.info(" -> creating item"); - switch (command.data.type) { case "bookmark": case "microsummary": + this._log.info(" -> creating bookmark \"" + command.data.title + "\""); let URI = makeURI(command.data.URI); newId = this._bms.insertBookmark(parentId, URI, @@ -634,17 +626,20 @@ BookmarksSyncService.prototype = { this._bms.setKeywordForBookmark(newId, command.data.keyword); if (command.data.type == "microsummary") { + this._log.info(" \-> is a microsummary"); let genURI = makeURI(command.data.generatorURI); let micsum = this._ms.createMicrosummary(URI, genURI); this._ms.setMicrosummary(newId, micsum); } break; case "folder": + this._log.info(" -> creating folder \"" + command.data.title + "\""); newId = this._bms.createFolder(parentId, command.data.title, command.data.index); break; case "livemark": + this._log.info(" -> creating livemark \"" + command.data.title + "\""); newId = this._ls.createLivemark(parentId, command.data.title, makeURI(command.data.siteURI), @@ -652,6 +647,7 @@ BookmarksSyncService.prototype = { command.data.index); break; case "separator": + this._log.info(" -> creating separator"); newId = this._bms.insertSeparator(parentId, command.data.index); break; default: @@ -1160,7 +1156,7 @@ BookmarksSyncService.prototype = { _onLogin: function BSS__onLogin(success) { if (success) { - this._log.config("Bookmarks sync server: " + this._dav.baseURL); + this._log.info("Bookmarks sync server: " + this._dav.baseURL); this._os.notifyObservers(null, "bookmarks-sync:login", ""); } else { this._os.notifyObservers(null, "bookmarks-sync:login-error", ""); diff --git a/services/sync/ILog4MozService.idl b/services/sync/ILog4MozService.idl index b5b6eef80315..43f2e17538c3 100644 --- a/services/sync/ILog4MozService.idl +++ b/services/sync/ILog4MozService.idl @@ -30,10 +30,11 @@ interface nsIFile; [scriptable, uuid(eeb0adbc-afa3-4326-9a52-040ce4855e9d)] interface ILogMessage : nsISupports { + attribute AString loggerName; attribute PRInt32 level; attribute AString levelDesc; attribute AString message; - attribute PRTime date; + attribute PRTime time; }; [scriptable, uuid(ac7f40df-49e7-4270-86ec-9c905047e70e)] @@ -54,7 +55,6 @@ interface ILogger : nsISupports { /* * Level constants - * Also here (in addition to the service) for convenience */ const PRInt32 LEVEL_FATAL = 70; const PRInt32 LEVEL_ERROR = 60; @@ -99,18 +99,6 @@ interface ILoggerRepository : nsISupports [scriptable, uuid(a60e50d7-90b8-4a12-ad0c-79e6a1896978)] interface ILog4MozService : nsISupports { - /* - * Level constants - */ - const PRInt32 LEVEL_FATAL = 70; - const PRInt32 LEVEL_ERROR = 60; - const PRInt32 LEVEL_WARN = 50; - const PRInt32 LEVEL_INFO = 40; - const PRInt32 LEVEL_CONFIG = 30; - const PRInt32 LEVEL_DEBUG = 20; - const PRInt32 LEVEL_TRACE = 10; - const PRInt32 LEVEL_ALL = 0; - /* * The root logger. Appenders added to this logger will be * inherited by all other loggers diff --git a/services/sync/ILog4MozService.idl~ b/services/sync/ILog4MozService.idl~ index 3c2f4d94c759..b5b6eef80315 100644 --- a/services/sync/ILog4MozService.idl~ +++ b/services/sync/ILog4MozService.idl~ @@ -25,10 +25,13 @@ #include "nsISupports.idl" +interface nsIFile; + [scriptable, uuid(eeb0adbc-afa3-4326-9a52-040ce4855e9d)] interface ILogMessage : nsISupports { attribute PRInt32 level; + attribute AString levelDesc; attribute AString message; attribute PRTime date; }; @@ -127,6 +130,8 @@ interface ILog4MozService : nsISupports ILogger getLogger(in AString name); IAppender newAppender(in AString kind, in IFormatter formatter); + IAppender newFileAppender(in AString kind, in nsIFile file, + in IFormatter formatter); IFormatter newFormatter(in AString kind); }; diff --git a/services/sync/ILog4MozService.xpt b/services/sync/ILog4MozService.xpt index 0e757a3806fd..0d212ff8414b 100644 Binary files a/services/sync/ILog4MozService.xpt and b/services/sync/ILog4MozService.xpt differ diff --git a/services/sync/Log4MozService.js b/services/sync/Log4MozService.js index c5b42f32ff35..5d0db9025110 100644 --- a/services/sync/Log4MozService.js +++ b/services/sync/Log4MozService.js @@ -49,14 +49,14 @@ const LEVEL_TRACE = 10; const LEVEL_ALL = 0; const LEVEL_DESC = { - 70: "FATAL ", - 60: "ERROR ", - 50: "WARN ", - 40: "INFO ", + 70: "FATAL", + 60: "ERROR", + 50: "WARN", + 40: "INFO", 30: "CONFIG", - 20: "DEBUG ", - 10: "TRACE ", - 0: "ALL " + 20: "DEBUG", + 10: "TRACE", + 0: "ALL" }; const ONE_BYTE = 1; @@ -202,9 +202,9 @@ Logger.prototype = { parent: null, - _level: -1, + _level: null, get level() { - if (this._level >= 0) + if (this._level != null) return this._level; if (this.parent) return this.parent.level; @@ -240,25 +240,25 @@ Logger.prototype = { }, fatal: function Logger_fatal(string) { - this.log(new LogMessage(LEVEL_FATAL, string)); + this.log(new LogMessage(this._name, LEVEL_FATAL, string)); }, error: function Logger_error(string) { - this.log(new LogMessage(LEVEL_ERROR, string)); + this.log(new LogMessage(this._name, LEVEL_ERROR, string)); }, warning: function Logger_warning(string) { - this.log(new LogMessage(LEVEL_WARN, string)); + this.log(new LogMessage(this._name, LEVEL_WARN, string)); }, info: function Logger_info(string) { - this.log(new LogMessage(LEVEL_INFO, string)); + this.log(new LogMessage(this._name, LEVEL_INFO, string)); }, config: function Logger_config(string) { - this.log(new LogMessage(LEVEL_CONFIG, string)); + this.log(new LogMessage(this._name, LEVEL_CONFIG, string)); }, debug: function Logger_debug(string) { - this.log(new LogMessage(LEVEL_DEBUG, string)); + this.log(new LogMessage(this._name, LEVEL_DEBUG, string)); }, trace: function Logger_trace(string) { - this.log(new LogMessage(LEVEL_TRACE, string)); + this.log(new LogMessage(this._name, LEVEL_TRACE, string)); } }; @@ -298,7 +298,6 @@ Appender.prototype = { function DumpAppender(formatter) { this._name = "DumpAppender"; this._formatter = formatter; - this._level = LEVEL_ALL; } DumpAppender.prototype = new Appender(); DumpAppender.prototype.doAppend = function DApp_doAppend(message) { @@ -313,19 +312,15 @@ DumpAppender.prototype.doAppend = function DApp_doAppend(message) { function ConsoleAppender(formatter) { this._name = "ConsoleAppender"; this._formatter = formatter; - this._level = LEVEL_ALL; } ConsoleAppender.prototype = new Appender(); ConsoleAppender.prototype.doAppend = function CApp_doAppend(message) { - //error or normal? - if(message.level > LEVEL_WARN){ + if (message.level > LEVEL_WARN) { Cu.reportError(message); - } else { - //get the js console - var consoleService = Components.classes["@mozilla.org/consoleservice;1"]. - getService(Ci.nsIConsoleService); - consoleService.logStringMessage(message); + return; } + Cc["@mozilla.org/consoleservice;1"]. + getService(Ci.nsIConsoleService).logStringMessage(message); }; /* @@ -337,7 +332,6 @@ function FileAppender(file, formatter) { this._name = "FileAppender"; this._file = file; // nsIFile this._formatter = formatter; - this._level = LEVEL_ALL; this.__fos = null; } FileAppender.prototype = new Appender(); @@ -381,7 +375,6 @@ function RotatingFileAppender(file, formatter, maxSize, maxBackups) { this._name = "RotatingFileAppender"; this._file = file; // nsIFile this._formatter = formatter; - this._level = LEVEL_ALL; this._maxSize = maxSize; this._maxBackups = maxBackups; } @@ -442,9 +435,11 @@ BasicFormatter.prototype = { this._dateFormat = format; }, format: function BF_format(message) { - // FIXME: message.date.toLocaleFormat(this.dateFormat) + " " + - - return message.levelDesc + " " + message.message + "\n"; + dump("time is " + message.time + "\n"); + let date = new Date(message.time); + return date.toLocaleFormat(this.dateFormat) + "\t" + + message.loggerName + "\t" + message.levelDesc + "\t" + + message.message + "\n"; } }; @@ -452,10 +447,11 @@ BasicFormatter.prototype = { * LogMessage * Encapsulates a single log event's data */ -function LogMessage(level, message){ +function LogMessage(loggerName, level, message){ + this.loggerName = loggerName; this.message = message; this.level = level; - this.date = new Date(); + this.time = Date.now(); } LogMessage.prototype = { QueryInterface: XPCOMUtils.generateQI([Ci.ILogMessage, Ci.nsISupports]), @@ -465,8 +461,9 @@ LogMessage.prototype = { return LEVEL_DESC[this.level]; return "UNKNOWN"; }, + toString: function LogMsg_toString(){ - return "LogMessage [" + this.date + " " + this.level + " " + + return "LogMessage [" + this._date + " " + this.level + " " + this.message + "]"; } };