Application logger.
Usage example:
const logger = require('utils/logger')({
level: 'DEBUG',
});
// Log a string message
logger.debug('Some debug message');
// Log an object
let obj = { foo: 'bar' };
logger.info(obj);
// Log a closure.
let a = 1;
logger.error(function() { return a; });
Methods
-
<static> debug(message)
-
Logs a message with the DEBUG log level.
Parameters:
Name Type Description message
string | Object | function Message to log.
-
<static> error(message)
-
Logs a message with the ERROR log level.
Parameters:
Name Type Description message
string | Object | function Message to log.
-
<static> fatal(message)
-
Logs a message with the FATAL log level.
Parameters:
Name Type Description message
string | Object | function Message to log.
-
<static> getLevel()
-
Retrieves logger level based on system settings.
Returns:
Logger level or
ERROR
if none defined.- Type
- Object
-
<static> info(message)
-
Logs a message with the INFO log level.
Parameters:
Name Type Description message
string | Object | function Message to log.
-
<static> log(level, message)
-
Logs a message with a given Utils.Logger.levels level. If the message is an object, it will be serialized into a JSON string. If the message is a function, it will evaluated in the logger's scope.
Parameters:
Name Type Description level
Utils.Logger.levels log level
message
string | Object | function log message
-
<static> trace(message)
-
Logs a message with the TRACE log level.
Parameters:
Name Type Description message
string | Object | function Message to log.
-
<static> warn(message)
-
Logs a message with the WARN log level.
Parameters:
Name Type Description message
string | Object | function Message to log.