michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: var LogController = {}; //create the logger object michael@0: michael@0: LogController.counter = 0; //current log message number michael@0: LogController.listeners = []; michael@0: LogController.logLevel = { michael@0: FATAL: 50, michael@0: ERROR: 40, michael@0: WARNING: 30, michael@0: INFO: 20, michael@0: DEBUG: 10 michael@0: }; michael@0: michael@0: /* set minimum logging level */ michael@0: LogController.logLevelAtLeast = function(minLevel) { michael@0: if (typeof(minLevel) == 'string') { michael@0: minLevel = LogController.logLevel[minLevel]; michael@0: } michael@0: return function (msg) { michael@0: var msgLevel = msg.level; michael@0: if (typeof(msgLevel) == 'string') { michael@0: msgLevel = LogController.logLevel[msgLevel]; michael@0: } michael@0: return msgLevel >= minLevel; michael@0: }; michael@0: }; michael@0: michael@0: /* creates the log message with the given level and info */ michael@0: LogController.createLogMessage = function(level, info) { michael@0: var msg = {}; michael@0: msg.num = LogController.counter; michael@0: msg.level = level; michael@0: msg.info = info; michael@0: msg.timestamp = new Date(); michael@0: return msg; michael@0: }; michael@0: michael@0: /* helper method to return a sub-array */ michael@0: LogController.extend = function (args, skip) { michael@0: var ret = []; michael@0: for (var i = skip; i