mongologger
A lightweight tool for sending logs to MongoDB
Last updated 4 years ago by rtannerf .
Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install mongologger 
SYNC missed versions from official npm registry.

mongoLogger

A lightweight tool for shipping logs to mongoDB.

Install

npm install mongologger

Usage

mongoLogger will look for a config.js and package.json in the working directory. It should look something like this:

module.exports = {
    mongologger: {
        dbaddress : "mongodb://localhost/",
        database : "logs",
        appname : "mongologger"
    }
};

Require mongoLogger (note the () on the require) and start logging:

var log = require('mongoLogger')()
log.trace('tracing...');
log.info('information');
log.warn('something doesnt look right');
log.error('houston we have a problem');
log.fatal('AGGGHHHH!!!');

Logs will be stored with the log level, message, hostname, appname, and version (from package.json) number:

{
  "_id" : ObjectId("55ca6b8485303dfc1bc4ccc7"),
  "logLevel" : 1,
  "message" : "pls halp is full of squirlz!",
  "hostname" : "honeypot",
  "appname" : "mongoLogger",
  "version" : "0.0.0"
}

Options & overrides

Additional options can be passed to basic logging functions. These options include:

  log.error('logging some errors...', {
    servicename: 'https://fooservice.com/api',
    request: 'POST /foo-the-bar',
    response: 'HTTP 403 - fooing the bar is forbidden!!!',
    requestID: '79c750df-d4cf-49fe-9b71-461ec43a7f25'
  });

Data pulled from the config.js can also be overriden:

  log.info('logging some info...', {
      hostname: 'hannibal',
      appname: 'souffle',
      version: '1.0.0'
  });

Tack

Additional information can be appended to the log by using the tack method:

  log.tack(id, 'corkboard', {
    thumbtacks: ["blue", "red", "green"]
  });

The object passed will be set in the additional property:

{
  "_id" : ObjectId("55d64f6de865edf430262d02"),
  "logLevel" : 1,
  "message" : "wall",
  "additional" :
  {
    "corkboard" { thumbtacks : ["blue", "red", "green"] }
  },
  "hostname" : "zeus",
  "appname" : "mongoLogger",
  "version" : "0.0.0"
}

Duration logging

mongoLogger also supports timing the duration of a function block by passing a watch object and logging the results as appropriate:

log.duration({ message: "database call took a long time!!", info: false, warn: 250}, function (watch) {
            setTimeout(function () {
                log.stop(watch)
              }, 500);
            });

By default, any errors thrown will log as logLevel: 3 (error). This can be overidden with warn: false, just as logging the duration of ALL calls under info can be overriden with info: false.

Current Tags

  • 0.0.8                                ...           latest (4 years ago)

9 Versions

  • 0.0.8                                ...           4 years ago
  • 0.0.7                                ...           4 years ago
  • 0.0.6                                ...           4 years ago
  • 0.0.5                                ...           4 years ago
  • 0.0.4                                ...           4 years ago
  • 0.0.3                                ...           4 years ago
  • 0.0.2                                ...           4 years ago
  • 0.0.1                                ...           4 years ago
  • 0.0.0                                ...           4 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 1
Last Month 10
Dependencies (1)
Dev Dependencies (10)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |