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-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:05:01 +08:00
|
|
|
var Logger = global.Logger = module.exports = {};
|
|
|
|
|
|
|
|
// 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) {
|
|
|
|
if (logger == null) { logger = new BasicLogger(); }
|
|
|
|
|
|
|
|
if (logger === false) {
|
|
|
|
this.logger = new NullLogger();
|
|
|
|
} else {
|
|
|
|
this.logger = logger;
|
2014-02-28 04:39:31 +08:00
|
|
|
}
|
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-05-14 10:05:01 +08:00
|
|
|
Logger.debug = function() {
|
|
|
|
var args = getArgs(arguments);
|
|
|
|
return this.logger.debug.apply(this.logger, args);
|
|
|
|
};
|
2013-10-25 05:25:42 +08:00
|
|
|
|
2014-05-14 10:05:01 +08:00
|
|
|
Logger.info = function() {
|
|
|
|
var args = getArgs(arguments);
|
|
|
|
return this.logger.info.apply(this.logger, args);
|
|
|
|
};
|
2013-10-25 05:25:42 +08:00
|
|
|
|
2014-05-14 10:05:01 +08:00
|
|
|
Logger.warn = function() {
|
|
|
|
var args = getArgs(arguments);
|
|
|
|
return this.logger.warn.apply(this.logger, args);
|
|
|
|
};
|
2013-10-25 05:25:42 +08:00
|
|
|
|
2014-05-14 10:05:01 +08:00
|
|
|
Logger.error = function() {
|
|
|
|
var args = getArgs(arguments);
|
|
|
|
return this.logger.error.apply(this.logger, args);
|
|
|
|
};
|
2013-10-25 05:25:42 +08:00
|
|
|
|
2014-05-14 10:05:01 +08:00
|
|
|
Logger.fatal = function() {
|
|
|
|
var args = getArgs(arguments);
|
|
|
|
return this.logger.fatal.apply(this.logger, args);
|
|
|
|
};
|