1.1.1 • Published 6 years ago

@sacoding/logging.js v1.1.1

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

logging.js

NPM Version Build Status

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');
1.1.1

6 years ago

1.1.0

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago