Fork me on GitHub
npm version NPM Downloads

An all-in-one JSON logging utility that supports ExpressJS HTTP logging, custom logging, provides multi-format output and an easy to use events API.

Documentation

Use Woodlot as an HTTP logger middleware

 var express = require('express');
 var app = express();
 var woodlot = require('woodlot').middlewareLogger;

 app.use(woodlot({
    streams: ['./logs/app.log'],
    stdout: false,
    routes: {
        whitelist: ['/api', '/dashboard'],
        strictChecking: false
    },
    format: {
        type: 'json',
        options: {
            cookies: true,
            headers: true,
            spacing: 4,
            separator: '\n'
        }
    }
}));
                    

It generates log output in JSON by default -

 {
    "responseTime": "4ms",
    "method": "GET",
    "url": "/api",
    "ip": "127.0.01",
    "body": {},
    "params": {},
    "query": {},
    "httpVersion": "1.1",
    "statusCode": 200,
    "timeStamp": "23/Apr/2017:20:46:01 +0000",
    "contentType": "text/html; charset=utf-8",
    "contentLength": "4",
    "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36",
    "referrer": null,
    "headers": {
        "host": "localhost:8000",
        "connection": "keep-alive",
        "accept-encoding": "gzip, deflate, sdch, br",
        "accept-language": "en-US,en;q=0.8,la;q=0.6"
    },
    "cookies": {
        "userId": "zasd-167279192-asknbke-0684"
    }
}
                    

Woodlot HTTP logger middleware also supports two other output formats - Apache Common and Apache Combined.
Please read the documentation for usage details and more.

Use Woodlot for custom logging

 var express = require('express');
 var app = express();
 var woodlotCustomLogger = require('woodlot').customLogger;
     
 var woodlot = new woodlotCustomLogger({
    streams: ['./logs/custom.log'],
    stdout: false,
    format: {
        type: 'json',
        options: {
            spacing: 4,
            separator: '\n'
        }
    }
});
     
app.get('/', function(req, res) {
    var id = 4533;
    woodlot.info('Data sent successfully');
    return res.status(200).send({ userId: id });
});
                    

Custom logging also generates log output in JSON by default -

 {
    "timeStamp": "23/Apr/2017:17:02:33 +0000",
    "message": "Data sent successfully",
    "level": "INFO"
 }
                    

Woodlot custom logger supports the following log levels -
Info Debug Warn Err
For details on more output formats and usage, please read the documentation.

Use Woodlot's events API to track log data at different points

 var woodlotEvents = require('woodlot').events;
 
 woodlotEvents.on('reqLog', function(log) {
    console.log('Generated log - ' + log);
 });
                    

Use those events to capture log data and send them to a third party service or save them in a database for aggregation and analysis

 var woodlotEvents = require('woodlot').events;
 
 woodlotEvents.on('err', function(log) {
    writeToMongoDb(log);

    // or 

    writeToMySql(log);

    // or 

    writeToLogStash(log);

    // or 

    writeToLoggly(log);
 });
                    

Woodlot emits events at various operations that can be used to track critical data. For usage details please read the documentation.

Copyright © 2017 AdPushup Inc.