lig leg log - json logging for idiots
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


logs of json


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")();"something happened!", {some: "other", things: "here"});
["2013-05-13T04:11:00.664Z","INFO","something happened!",{"some":"other","things":"here"}]


Available via npm:

$ npm install leg

Or via git:

$ git clone git:// node_modules/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});


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}]


  • 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 (default null)

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), 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}]


  • text - same as text in log
  • info - same as info in log

Creating your own

log.silly = log.bind(log, "SILLY");
log.silly("yippee", {woo: "hoo"});


3-clause BSD. A copy is included with the source.