npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mongologger

v0.0.8

Published

A lightweight tool for sending logs to MongoDB

Downloads

12

Readme

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.