@sacoding/logging.js
v1.1.1
Published
Simple logger for frontend applications
Downloads
1
Readme
logging.js
logging.js
is a library providing logging for frontend applications
Installation
npm install --save @sacoding/logging.js
Usage
To use logging.js
import it in javascript file and get default logger by calling getLogger
method.
import Logging from '@sacoding/logging.js';
const loggger = Logging.getLogger();
logger.debug('foo', { bar: 1 });
Defining new loggers
Logging
class has static method setLogger
which can be used to define new loggers.
Each logger has to have following static methods:
debug
,info
,notice
,warning
,error
,critical
,alert
,emergency
.
Convention used in predefined loggers is to handle two parameters for each method:
- first for
message
which is string, - second for
context
which is object.
import Logging from '@sacoding/logging.js';
class FooLogger {
static emergency = () => {};
static alert = () => {};
static critical = () => {};
static error = () => {};
static warning = () => {};
static notice = () => {};
static info = () => {};
static debug = () => {};
}
Logging.setLogger('foo', FooLogger, false);
Third parameter of Logging::setLogger
method is used to set new logger as default one if it is true
.
To log with new logger call:
const fooLogger = Logging.getLogger('foo');
fooLogger.debug('bar');