Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for log levels. Fixes #51 #80

Merged
merged 1 commit into from
Feb 25, 2019
Merged

Add support for log levels. Fixes #51 #80

merged 1 commit into from
Feb 25, 2019

Conversation

klaudiosinani
Copy link
Owner

Description

The PR introduces the ability to display/hide logged messages through a scaled logging level system. The logging level can be defined through the logLevel option, which is of type String & it is part of the configuration object pass to the initialization of a Signale instance, and can be one of the following 5 strings:

  • 'info' - Displays all the messages of all logger types.
  • 'timer' - Displays only the messages of time, timeEnd, debug, warn, error & fatal logger types.
  • 'debug' - Displays only the messages of debug, warn, error & fatal logger types.
  • 'warn' - Displays only the messages of warn, error & fatal logger types.
  • 'error' - Displays only the messages of error & fatal logger types.

The default value is 'info' for the logLevel Signale configuration option, as well as for the logLevel attribute of custom logger types. The option is inherited from parent to child instance whenever the unary signale.scope() function is used.

const {Signale} = require('signale');

const signale = new Signale({
  scope: 'parent',
  logLevel: 'debug' // Only `debug`, `warn` & `error` messages will be logged
});

signale.info('Info message');
//=>
signale.time('timer');
//=>
signale.timeEnd('timer');
//=>
signale.debug('Debug message');
//=> [parent] › ⬤  debug     Debug message
signale.warn('Warn message');
//=> [parent] › ⚠  warning   Warn message
signale.error('Error message');
//=> [parent] › ✖  error     Error message

// `child` logger inherits the `debug` log level of its parent instance
const child = signale.scope('child');

child.info('Info message');
//=>
child.time('test');
//=>
child.timeEnd('test');
//=>
child.debug('Debug message');
//=> [child] › ⬤  debug     Debug message
child.warn('Warn message');
//=> [child] › ⚠  warning   Warn message
child.error('Error message');
//=> [child] › ✖  error     Error message

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant