2.0.0 • Published 9 months ago

@map-colonies/js-logger v2.0.0

Weekly downloads
-
License
ISC
Repository
github
Last release
9 months ago

js logger

JavaScript and TypeScript logger for MapColonies based on pino.

API documentation

Check the autogenerated documentation here.

Usage

import jsLogger from '@map-colonies/js-logger';

const logger = jsLogger();

logger.info('hello world');

logger.error({hello: 'world'});

Logging errors

One of the features of the logger is the ability to parse error objects and format them accordingly. To allow the logger to identify the error, add it to the log object under the err key.

try {
  // complex code
} catch (error) {
  logger.error({msg: "oh noes", err: error});
}

For more detailed usage check the pino documentation.

Configuration

nametypedefault valuedescription
enabledbooleantruedetermines if logging is enabled
levelstring'info'specifies the logging level
redactarrayundefineddefines paths to redact from log output
hooksobjectundefinedhooks for customizing log behavior
baseobject{pid: process.pid, hostname: os.hostname}base properties to include in log output
mixinfunctionundefinedfunction to add custom properties to log output
prettyPrintbooleanfalseenables pretty-printing of log output
pinoCallerbooleanfalseincludes the caller's file and line number in log output