log!
logbang (aka log!) is a simple, structured logging library. This repository implements a logger for node.js and browsers. It also acts as the reference implementation for log!
Install
npm install logbang
Usage
Create a basic logger with logbang and use the handy level functions to emit structured JSON log lines:
// examples/simple.js ; // create a named logger with some base contextconst logger = ; logger;logger;logger; // create a child logger which will be named service:api:db and combines the// parent logger context with its ownconst dblogger = logger;dblogger;
You can integrate logbang in your webservice quite easily:
// examples/server.js const express = ;const ms = ;const onHeaders = ;const prettyHrtime = ;const uuidv4 = ;// using commonjs, you will need to re-alias the default es5 exportconst default: Logger = ; const app = ; const logger = ; // add a correlation id on incoming requestsapp; app; app;app; app; app;
CLI
When running code that uses logbang to emit log events, you may prefer to see human-friendly output in the console. Use logbang CLI app and pipe your process's output to it. You can download the app for you platform from here: https://github.com/logbang/logbangcli/releases
Assuming you've placed the script in your PATH (for example /usr/local/bin/logbang
), you can run the above simple example like so:
node examples/simple.js | logbang
You should see the follow output: