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

yocto-logger

v3.0.0

Published

Ready to use logger utility based on winston.

Downloads

64

Readme

NPM

alt text Code Climate Test Coverage Issue Count Build Status

Overview

This module is a part of yocto node modules for NodeJS.

Please see https://www.npmjs.com/~yocto for complete list of available module (completed day after day).

This module manage your own logger request on your node app.

This module his based on winston package.

IMPORTANT : This module is not a complete reimplantation of winston we only use winston for the core process.

IMPORTANT : This module shared logger by default in next major release group logger will be add

Motivation

In all of our project we use a logger library like winston. But all the time we need to configure again and again the same library.

That why we decided to create yocto-Logger.

This tool is designed to be a very very simple and pre-configured and ready to use tool based on the universal logging library winston.

Configuration : console transport

By default a console is configured with these options : (Cf. winston & momentjs documentation for more details)

{
  level             : 'debug',
  handleExceptions  : false,
  json              : false,
  showLevel         : true,
  silent            : false,
  timestamp         : function () {
    // return special timestamp format
    return moment().format('YYYY/MM/DD HH:mm:ss');
  }
};

Configuration : daily rotate transport

By default a daily rotate transport is configured with these options : (Cf. winston & momentjs documentation for more details)

{
  name              : 'default-daily-rotate-transport',
  level             : 'verbose',
  dirname           : './',
  filename          : uuid.v4(), // default name if name is not given
  handleExceptions  : true,
  json              : false,
  maxsize           : 5242880,
  maxFiles          : 5,
  colorize          : true,
  datePattern       : '-yyyy-MM-dd.log',
  timestamp         : function () {
    // return special timestamp format
    return moment().format('YYYY/MM/DD HH:mm:ss');
  }
};

Logging Method

Avaiblable methods are :

  • error (for error message)
  • warning (for warning message)
  • info (for information message)
  • debug (for debug message)
  • verbose (for normal message)
var logger = require('yocto-logger');
// error message
logger.error('Hello world');
// warning message
logger.warning('Hello world');
// info message
logger.info('Hello world');
// debug message
logger.debug('Hello world');
// verbose message
logger.verbose('Hello world');
// banner message
logger.banner('Hello world');

Banner Method

To display on console.log a more significant message we implemened a banner method. You can customize style (color and background color) of message but is not save on available transports.

var logger = require('yocto-logger');
// banner usage
logger.banner("Banner customized",{ color: "red" , bgColor: "white" });

Transport : Adding a new daily rotate transport

var logger = require('yocto-logger');

// add new daily rotate transport with default config
logger.addDailyRotateTransport();

// add new daily rotate transport and process new action when async is finish
logger.addDailyRotateTransport().then(function(success) {
    // your process here
}, function(error) {
    // error process here
});

// add new daily transport on specific path + changing filename and more options
logger.addDailyRotateTransport('/your-new-path-here', 'your-file-name-here', {});

Change level manually

You can change current logger level manually by method setLogLevel(name).

Property name of this function must be one of these values :

  • error (for error message)
  • warning (for warning message)
  • info (for information message)
  • debug (for debug message)
  • verbose (for normal message)

For example if we need to set current logger instance to error level :

var logger = require('yocto-logger');

logger.setLogLevel('error');
// YOUR Extra code here

Utility Methods

For a better usage we can interact with all transport by utility methods. Methods available are :

  • more :to change the log level to a higher level
  • less : to change the log level to a less level
  • enableConsole : to enable console transport if is disable
  • disableConsole : to disable console transport if is enable
  • enableExceptions : to enable catch exception on logger if is disable
  • disableExceptions : to disable catch exception on logger if is enable
var logger = require('yocto-logger');

// Less & more - initial level is debug
logger.more(); // level change to verbose
logger.less(); // level change to debug

// Others method
logger.enableConsole();
logger.disableConsole();
logger.enableExceptions();
logger.disableExceptions();