0.1.11 • Published 5 years ago
@ingentis/log v0.1.11
Description
Allows log levels to be disabled based on the build environment (e.g., disable debug logs in production).
Usage
Install the package.
$ npm i @ingentis/log
Import and configure the Log
class at the entry point of your application.
import { Log } from '@ingentis/log';
Log.configure({ levels: 'warn|error' });
Send logs to the Log
class as you would to the console
class. If a log level
was omitted from the configuration, corresponding logs will be ignored.
Log.info('This is an info log.'); // Will not appear.
Log.warn('This is a warn log.'); // Appears as normal.
Configuration
{
levels: 'info|warn|error',
tags: true
}
levels : string = 'debug|info|log|warn|error'
Log levels delimited by a pipe (
|
). Log levels include:debug
info
log
warn
error
tags : boolean = false
If true, logs are prefixed with the name of the module. When your package is installed as a dependency, logs are prefixed with your package name instead.
Log.debug('This is a log from index.js.'); // [index] This is a log from index.js.
FAQ
What about dependencies using Log?
Configuration is scoped to the directory of the calling module; packages cannot affect other packages' logs.