mmir.Logging
A Logger factory.
- See:
Example
//use logger
var Logger = mmir.require('mmirf/logger');
var log = Logger.create('example');
if(log.isVerbose()) log.debug('test');//will write the message to debug-console)
log.error(new Error());//will write the error (including its stack) to error console)
//example for setting up a logger in a requirejs-module:
define(['mmirf/logger', 'module'], function(Logger, module){
var logger = Logger.create(module);
//this would create the same logger-object:
// Logger.create(module.id, module.config(module).logLevel);
//use the logger instance...
//create / retrieve the same logger
var sameLogger = Logger.create(module.id);
});
Members
-
_level
-
the (global) logging level 0: verbose 1: debug 2: info 3: warn 4: error 5: critical 6: disabled
Methods
-
create(loggerName, logLevel){mmir.tools.Logger}
-
Creates a
mmir.tools.Logger
instance. If a logger forloggerName
already exists, the existing logger is returned (instead of creating a new one).Name Type Description loggerName
String | Object optional If String: a name / ID for the logger that should be created / retrieved.
If Object: an requirejsmodule
object, i.e. should contain propertiesid
(String) which will set theloggerName
, and a property/functionconfig
(Function) that returns an object with propertylogLevel
(i.e.config().logLevel
should be valid).
If omitted, the default logger will be returned.logLevel
String | LogLevel optional a name / ID for the logger that should be created / retrieved. If omitted, the default logger will be returned. Returns:
Type Description mmir.tools.Logger the created (or retrieved) logger -
debug()
-
Print debug message with default logger.
-
error()
-
Print error with default logger.
-
getDefaultLogLevel(){Number}
-
Sets the default log-level.
Returns:
Type Description Number the log level: a number between 0 (verbose) and 6 (disabled) -
info()
-
Print information message with default logger.
-
log()
-
Print log output with default logger.
-
setDefaultLogLevel(theLevel)
-
Sets the default log-level. This setting is used by loggers, that do not have a specific log-level set.
Name Type Description theLevel
String | Number if NUMBER, the log level as a number between 0 (verbose) and 6 (disabled) if STRING, the logging level as a string (see getLevel
) -
verbose()
-
Print verbose output with default logger.
-
warn()
-
Print warning message with default logger.