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

marvin-logger

v3.3.1

Published

Simple, effective, colorful and cross-platform logger for nodejs

Downloads

38

Readme

marvin-logger

npm license github-issues travis-status

Simple, effective, colorful and cross-platform logger for nodejs

nodei.co

stars forks forks

Features

screenshot macOS

marvin-logger is a simple, effective, colorful and cross-platform logger for nodejs which:

  • Log to console
  • Log to file
  • Works as a middleware with expressjs
  • "Rotate" log files
  • Colorize logs by levels (debug, info, warning, error, important, http)

Install

npm install --save marvin-logger

Usage

Include library and create a logger instance. By default, you'll log only to your console.

var Marvin = require('marvin-logger'),
    logger = new Marvin();

To log to file, you have to define the output directory:

var Marvin = require('marvin-logger'),
    logger = new Marvin({
      logOutputDirectory: './logs'
    });

Default log format is {{DATETIME}} {{PID}} {{LOG}} with :

  • {{DATETIME}} : Date + time (for file log) or time (for console log)
  • {{PID}} : Current process PID (useful for clusters)
  • {{LOG}} : Log message

Log format can be specified at init time :

var Marvin = require('marvin-logger'),
    logger = new Marvin({
      logFormat: '{{DATETIME}} - {{LOG}}'
      logOutputDirectory: './logs'
    });

Log some debug data :

logger.debug('[debug] message');
logger.debug('Another debug message with object', {foo: 'bar'});

debug() can be replaced with info(), warn(), error(), important() and http(). Every methods use the same syntax as console.log().

You can define a minimal log level by passing the level option to Marvin:

var Marvin = require('marvin-logger'),
    logger = new Marvin({
      level: 'error',
      logOutputDirectory: './logs'
    });

In this example, only error(), important() and http() will be able to display information.

important() and http() are always shown. You can use them to display important data like critical states or http access (or what ever you want).

To change log level :

logger.setLogLevel('info'); // level >= INFO
logger.setLogLevel('none'); // only HTTP & IMPORTANT

If the log data begins with brackets ('[...]'), only the text between the brackets will be colorized.

logger.important('[MyApp] Super important log message'); // Only 'MyApp' will be shown in magenta  

To use marvin-logger as an expressjs middleware logger:

var express = require('express'),
    app = express(),
    logger = new Marvin();

app.use(logger.expressMiddleWare());

To filter, you can specify wich string or Regex your messages should match, one filter per log level:

var Marvin = require('marvin-logger'),
    logger = new Marvin({
      errorFilter: 'my-filter-string',
      debugFilter: 'my-filter-regex',
    });

Available filters are : debugFilter, infoFilter, warnFilter, errorFilter, importantFilter and httpFilter.

Messages not matching filters are neither written to console nor file.

To change a filter after init :

logger.setDebugFilter(null);
logger.setInfoFilter('my-string');
logger.setWarnFilter('my-string');
logger.setErrorFilter('');
logger.setImportantFilter(/my-[regx]/i);
logger.setHttpFilter(/[^htp]/i);

To use marvin-logger as a singleton insance :

var logger = require('marvin-logger').sharedInstance;
logger.setLogOutputDirectory('logs');
logger.setLogLevel('debug');

Scripts

  • npm run test : mocha
  • npm run autotest : supervisor -q -n exit -x mocha -- --reporter=nyan
  • npm run autotest-cov : supervisor -w ./index.js,./test -q -n exit -x istanbul -- cover _mocha
  • npm run readme : node ./node_modules/.bin/node-readme

Dependencies

Package | Version | Dev --- |:---:|:---: colors | ^1.1.2 | ✖ file-stream-rotator | 0.0.7 | ✖ node-json-color-stringify | ^1.1.0 | ✖ on-finished | ^2.3.0 | ✖ on-headers | ^1.0.1 | ✖ express | ^4.14.0 | ✔ istanbul | ^0.4.5 | ✔ mocha | ^3.2.0 | ✔ node-readme | ^0.1.9 | ✔ supertest | ^2.0.1 | ✔ supervisor | ^0.12.0 | ✔

Contributing

Contributions welcome; Please submit all pull requests against the master branch. If your pull request contains JavaScript patches or features, you should include relevant unit tests.

Author

René BIGOT

License

  • MIT : http://opensource.org/licenses/MIT