leg v1.1.0
leg
logs of json
Overview
leg! leg because lel! leg is a stupidly simple JSON-based logging thingy. It works the way I want it to, and you might also garner some utility from it. If not, that's fine.
Super Quickstart
var log = require("leg")();
log.info("something happened!", {some: "other", things: "here"});["2013-05-13T04:11:00.664Z","INFO","something happened!",{"some":"other","things":"here"}]Installation
Available via npm:
$ npm install leg
Or via git:
$ git clone git://github.com/deoxxa/leg.git node_modules/leg
API
leg
Creates a new logging function thing. Optionally takes a writable stream to
output to as an argument. By default, will use process.stderr. The return
value is a function that you can use to log things!
leg([stream], [options]);// instantiate with default process.stderr output
var log = leg();
// instantiate with different output
var log = log(process.stdout);
// instantiate with options
var log = log(null, {object: true});log
This is the return value of leg(). It takes three arguments, with the last one
being optional. It also has a few convenience things tacked onto it, read on
below for more info on them.
log(level, text, [info]);// log without any context information
log("EMERGENCY", "there are very few donuts left");
// log with some useful context data
log("EMERGENCY", "there are very few donuts left", {donutCount: 3});["2013-05-13T04:13:51.640Z","EMERGENCY","there are very few donuts left",null]
["2013-05-13T04:13:51.640Z","EMERGENCY","there are very few donuts left",{"donutCount":3}]Arguments
- level - the coarse level of the log message. e.g. "ERROR"
- text - the main text body of the message. e.g. "received request"
- info - any kind of
JSON.stringify-able value (defaultnull)
debug info warn error
These are all properties of the log function. They just provide a suggested
set of log levels. You can even create your own!
log.debug(text, info)
log.info(text, info)
log.warn(text, info)
log.error(text, info)log.debug("some debugging info", {someMetric: 12345});["2013-05-13T04:20:50.477Z","DEBUG","some debugging info",{"someMetric":12345}]Arguments
- text - same as
textinlog - info - same as
infoinlog
Creating your own
log.silly = log.bind(log, "SILLY");
log.silly("yippee", {woo: "hoo"});["2013-05-13T04:22:36.299Z","SILLY","yippee",{"woo":"hoo"}]License
3-clause BSD. A copy is included with the source.
Contact
- GitHub (deoxxa)
- Twitter (@deoxxa)
- Email (deoxxa@fknsrs.biz)