1.0.1 • Published 3 days ago

eris-logger v1.0.1

Weekly downloads
-
License
ISC
Repository
github
Last release
3 days ago

ErisLogger

About package

ErisLogger is a logging tool that makes life easier. It has under the hood a pino package for writing logs to a file as well as tools for console logging.

Installation

npm i eris-logger

Example

General concepts

The default settings create a logger that will write to the terminal and file. The logger also includes the following settings:

  • Terminal Settings
  • FileLogger settings
  • Date format
  • Logging level
const logger = new ErisLogger({
  terminal: { ... },
  file: { ... },
  options: {},
});

Logging levels can be different: for example, one configuration can be configured for a terminal, another for a file, or you can set a global one for all.

How it looks like:

const logger = new ErisLogger({
  terminal: {
    use: true,
    options: {
      levels: ['info', 'debug']
    }
  },
  file: {
    use: true,
    options: {
      levels: ['warning', 'error', 'critical']
    } 
  },
  options: {},
});

Or global:

const logger = new ErisLogger({
  options: {
    levels: ['info', 'alert', 'debug', 'warning', 'error', 'critical']
  },
});

Terminal

To begin with, let's create an instance of the ErisLogger class, after which we indicate that we need to output logs in the terminal.

const logger = new ErisLogger({ terminal: { use: true, options: {} }, options: {} });

This is how the default settings look like:

const terminalConfig = {
  use: true,
  options: {
    colors: {
      info: 'greenBright',
      alert: 'blueBright',
      debug: 'blackBright',
      warning: 'yellow',
      error: 'redBright',
      critical: 'bgRed',
    },
    levels: ['info', 'alert', 'debug', 'warning', 'error', 'critical'],
  },
};


const logger = new ErisLogger({ terminal: terminalConfig, options: {} });

List of all available colors:

export type TerminalColors = 'black' | 'red' | 'green' | 'yellow' | 'blue' | 'magenta' | 'cyan' | 'white';
export type TerminalBgColors = 'bgBlack' | 'bgRed' | 'bgGreen' | 'bgYellow' | 'bgBlue' | 'bgMagenta' | 'bgCyan' | 'bgWhite';

export type TerminalBrightColors =  | 'blackBright'  | 'redBright'  | 'greenBright'  | 'yellowBright'  | 'blueBright'  | 'magentaBright'  | 'cyanBright'  | 'whiteBright';
export type TerminalBgBrightColors =  | 'bgBlackBright'  | 'bgRedBright'  | 'bgGreenBright'  | 'bgYellowBright'  | 'bgBlueBright'  | 'bgMagentaBright'  | 'bgCyanBright'  | 'bgWhiteBright';

FileLogger

To begin with, let's create an instance of the ErisLogger class, after which we indicate that we need to output logs in the file.

const logger = new ErisLogger({ file: { use: true, options: {} }, options: {} });

This is how the default settings look like:

const fileConfig = {
  use: true,
  options: {
    dir: '/logs.log',
    colorize: true,
    levels: ['info', 'alert', 'debug', 'warning', 'error', 'critical'],
  },
};


const logger = new ErisLogger({ file: fileConfig, options: {} });

Methods

// Info log
logger.info({ title: 'INFO', message: 'info string', params: { foo: 'bar' } });

// Alert log
logger.alert({ title: 'ALERT', message: 'alert string', params: { foo: 'bar' } });

// Debug log
logger.debug({ title: 'DEBUG', message: 'debug string', params: { foo: 'bar' } });

// Warning log
logger.warning({ title: 'WARNING', message: 'warning string', error: new Error('Some warning') });

// Error log
logger.error({ title: 'ERROR', message: 'error string', error: new Error('Some error') });

// Critical log
logger.critical({ title: 'CRITICAl', message: 'critical error string', error: new Error('Some critical error') });
1.0.1

3 days ago

1.0.0

3 days ago

0.1.8

10 months ago

0.1.7

10 months ago

0.1.6

10 months ago

0.1.2

12 months ago

0.1.4

12 months ago

0.1.3

12 months ago

0.1.5

12 months ago

0.1.1

1 year ago

0.1.0

1 year ago

0.0.9

1 year ago

0.0.8

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago