2013-10-25 05:25:42 +08:00
|
|
|
/*
|
|
|
|
* logger
|
|
|
|
* cylonjs.com
|
|
|
|
*
|
|
|
|
* Copyright (c) 2013 The Hybrid Group
|
|
|
|
* Licensed under the Apache 2.0 license.
|
|
|
|
*/
|
|
|
|
|
2014-02-28 04:39:31 +08:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
var getArgs = function(args) {
|
|
|
|
return args.length >= 1 ? [].slice.call(args, 0) : [];
|
2014-03-08 15:33:59 +08:00
|
|
|
};
|
2014-02-28 04:39:31 +08:00
|
|
|
|
2014-10-25 05:54:56 +08:00
|
|
|
var levels = ["debug", "info", "warn", "error", "fatal"];
|
|
|
|
|
2014-05-14 10:05:01 +08:00
|
|
|
var BasicLogger = require('./logger/basic_logger'),
|
|
|
|
NullLogger = require('./logger/null_logger');
|
|
|
|
|
2014-02-28 04:39:31 +08:00
|
|
|
// The Logger is a global object to facilitate logging stuff to the console (or
|
|
|
|
// other output) easily and consistently. It's available anywhere in Cylon, as
|
|
|
|
// well as in external modules that are loaded into Cylon
|
2014-05-14 10:44:40 +08:00
|
|
|
var Logger = module.exports = {};
|
2014-05-14 10:05:01 +08:00
|
|
|
|
|
|
|
// Public: Creates a Logger instance and assigns it to @logger
|
|
|
|
//
|
|
|
|
// logger - logger object to use. Defaults to a BasicLogger, or a NullLogger if
|
|
|
|
// false is supplied
|
|
|
|
//
|
|
|
|
// Returns the new logger instance
|
|
|
|
Logger.setup = function setup(logger) {
|
2014-10-25 05:02:03 +08:00
|
|
|
if (logger == null) { logger = BasicLogger; }
|
2014-05-14 10:05:01 +08:00
|
|
|
|
2014-10-25 05:54:56 +08:00
|
|
|
this.logger = logger || NullLogger;
|
2013-10-25 05:25:42 +08:00
|
|
|
|
2014-05-14 10:05:01 +08:00
|
|
|
return this.logger;
|
|
|
|
};
|
2013-10-25 05:25:42 +08:00
|
|
|
|
2014-05-14 10:05:01 +08:00
|
|
|
Logger.toString = function() {
|
|
|
|
return this.logger.toString();
|
|
|
|
};
|
2013-10-25 05:25:42 +08:00
|
|
|
|
2014-10-25 05:54:56 +08:00
|
|
|
levels.forEach(function(level) {
|
|
|
|
Logger[level] = function() {
|
|
|
|
return this.logger[level].apply(this.logger, arguments);
|
|
|
|
}
|
|
|
|
});
|