readme.md

logger.js

Simple logger can be used as wrapper for console, adds log output levels, multiple targets and history. Will default to use console, but you can add your own custom targets instead.

This library is written entirely in ECMAScript 6+, so if you need support for older browsers you need something like Babel.

API

Contructor

new Logger(logLevel, ...targets)

Parameters

logLevel

Optional. Log messages from specified level (ordered):

LogLevel.log

LogLevel.info

LogLevel.warn

LogLevel.error

Default: LogLevels.log

targets

Optional. Targets to output to, multiple can be specified: new Logger(LogLevels.log, target1, target2)

Default: console

Usage

importLoggerfrom'logger'constlogger=newLogger()
logger.log('log line 1')
logger.info('log line 2')
logger.warn('log line 3')
logger.error('log line 4')

Log levels

You can choose only to log above a certain level. To only print warnings and errors:

importLogger, {LogLevels} from'logger'constlogger=newLogger(LogLevels.warn)
logger.log('log line 1') // will not be loggedlogger.info('log line 2') // will not be loggedlogger.warn('log line 3')
logger.error('log line 4')

Multiple targets

You can choose to log to multiple targets, for instance sending logs to both console and a logging server.