4.0.0 • Published 9 months ago

@bonniernews/exp-logger v4.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
9 months ago

exp-logger

Simple logger package to unify how logging is done with (configurable) remapping

NPM


defaults

  • trace -> DEBUG
  • debug -> DEBUG
  • info -> INFO
  • warn -> WARNING
  • error -> ERROR
  • fatal -> CRITICAL

options

  logLevel // defaults to info
  mixin  // pino mixins, passed down to pino as is
  formatLog  // pino formatter.log function, passed down to pino as is

example

const logger = require('@bonniernews/exp-logger')()

logger.info("Hello world")

/* 
-- expected output
[15:19:13.240] INFO: Hello world
*/

Format the log object

To change the shape of the log object to match gcp error-reporting structure or similiar, use formatLog

const expLogger = require('@bonniernews/exp-logger');

const logger = expLogger({
    formatLog: (obj) => {
        if (!obj.err) {
           return obj;
        }
        const stackTrace = obj.err?.stack;
        return {
            ...obj,
            ...(stackTrace && { stack_trace: stackTrace }),
        };
    }
);

logger.error(new Error('Something wrong'));
4.0.0

9 months ago

3.0.3

9 months ago

3.0.2

1 year ago

3.0.1

1 year ago

3.0.0

2 years ago

2.0.0

3 years ago

1.0.0

3 years ago