Logger

The Logger class

Logger

Type: Logger

Parameters
options (object?) Configuration options for the logger.
Name Description
options.base object (default null) An object with base properties that will be printed with every log line.
options.name string (default undefined) The name of the logger. It is a good practice to give names for easier identification of modules for example.
options.level string (default 'info') The log level. One of 'fatal', 'error', 'warn', 'info', 'debug', 'trace' or 'silent'.
options.file string (default undefined) The location of the log file. If not given, logs will be outputted to std out/err.
options.prettyPrint boolean? Whether to pretty print the logs or output json lines
options.redact (object | array)? The object props to redact from the output. As an array, the redact option specifies paths that should have their values redacted from any log output. Each path must be a string using a syntax which corresponds to JavaScript dot and bracket notation. If an object is supplied, three options can be specified: paths , censor and remove .
options.redact.paths array Required. An array of paths.
options.redact.censor (string | function | undefined) (default '[Redacted]') Censor option will overwrite keys which are to be redacted.
options.redact.remove boolean (default false) Instead of censoring the value, remove both the key and the value.
options.browser object (default undefined) Config for browsers only.
options.browser.write (function | object)? Instead of passing log messages to console.log they can be passed to a supplied function. If write is an object, it can have methods that correspond to the levels. When a message is logged at a given level, the corresponding method is called. If a method isn't present, the logging falls back to using the console.
Example
import Logger from '@qfin/logger';

// this creates a parent logger with name (my-app)
const logger = new Logger({ name: 'my-app', level: 'info' });

logger.info('Hello world from my awesome app!');
logger.debug('This will not be printed');

// --- somewhere else in the codebase

import Logger from '@qfin/logger';

// this creates a child logger with name (db) and it takes the log-level of the parent logger
const dbLogger = new Logger({ name: 'db' });

dbLogger.info('Successfully connected to Database: ', `${db.host}:${db.port}/${db.name}`);

// --- static logger usage

import Logger from '@qfin/logger';

// If logger is already initialized, then the parent logger reference will be used in this static call
// otherwise, a default parent logger will be initialized and then that will be used for logging
Logger.log('This is a static logger log');
Static Members
log(arg0?, args?)
trace(arg0?, args?)
debug(arg0?, args?)
info(arg0?, args?)
warn(arg0?, args?)
error(arg0?, args?)
fatal(arg0?, args?)
Instance Members
log(arg0?, args?)
trace(arg0?, args?)
debug(arg0?, args?)
info(arg0?, args?)
warn(arg0?, args?)
error(arg0?, args?)
fatal(arg0?, args?)