logawesome
logawesome
is a rudimentary logging implementation and still WIP.
Why another Logger?
Some loggers are doing too much or specific work.
logawesome
is:
- not having one global logging configuration, but multiple if desired
- syntactic sugar easy to use logger
- minimal functional interface for dispatching to so called appenders
- unrestricted in terms of log levels or log messages
Example:
logger `INFO` `connecting to `;
Usage
npm install logawesome
We use npm package debug
. To make me verbose use DEBUG=logawesome
.
Creating a log system
; const logSystem = ;logSystem;logSystem;logSystem;
Console Appender
Using moment
as date formatter.
; const appender = ; logSystem;
File Stream Appender
; const appender = ; logSystem;
How it works
A logger can be invoked like this:
logger `INFO` `connecting to `;
The LogSystem
invokes all appenders deferred (process.nextTick
). Log message is enhanced with:
- a timestamp (whatever you passed to
new LogSystem(timestampFn)
, orDate.now()
per default) - an existing immutable context, updated by
logger.set(...)
or branched bylogger.branch()
An Appender
simply is a function, taking 6 arguments:
- timestamp: number, produced by
LogSystem
- context: object, immutable context of the log entry
- levelTpls: array of strings, first parameter of a template string
- levelPlaceholders: array, second parameter of a template string
- msgTpls: array of strings, first parameter of a template string
- msgPlaceholders: array, second parameter of a template string
It's the appender's responsibility to aggregate information.
At current logawesome
is shipping with 2 appenders.
- file stream appender: writing logs to time dependant rotating files
- console appender: writing logs to console
Both using composition:
Appender = Transformer -> Formatter -> Writer
- Transformer: context aggregation according to template string
- Formatter: produces log message
- Writer: writes it to the target
Plans
- micro packages, move appender logic to external packages
- ELK stack support
- syslog support