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

winston-logger-setup

v1.1.0

Published

Logger setup using winston and loggly

Downloads

62

Readme

winston-logger-setup

This is a logger setup using winston and loggly which makes it easier for an application to maintain log files. There are separate log files for warn logs, debug logs, error logs and info logs. Cloud log to www.loggly.com can also be added with correct settings and there is also the plain old console log for console view only.

Quick jumps

Installation

npm install winston-logger-setup
          OR
npm install winston-logger-setup --save

Config

The package looks for a config-log.js file in the config folder inside root of the application for configuration settings. If found and if it contains the specified properties that are required for the package, it will use those values, else the default configurations values that are bundled with the package will be used instead. An example of config-log.js file:

module.exports = {
	logLevels: {
        levels: {
            error: 0,
            warn: 0,
            info: 0,
            debug: 0,
            cnsl: 0
        },
        colors: {
            error: 'red',
            warn: 'yellow',
            info: 'blue',
            debug: 'white',
            cnsl: 'green'
        }
    },
    cloud: {
        inputToken: 'j88m3-sjjhj33-dsfjj33',
        subdomain: 'LogglySubDomain'
    },
    logFolder: '/log/'
};

logLevels

contains two properties - levels and colors

levels refers to the importance of the log, 0 being the most important and 5 being the least. If the importance of log is less, only the log file is updated while the console does not show the log. The level values in the above config example are also the default values bound with the package.

colors refers to the color of the log shown in the console. Only standard console colors are available. The color values in the above config example are also the default values bound with the package.

cloud

contains configuration for loggly based cloud log setup. It contains two properties - inputToken and subdomain. The default configuration bound with the package does not contain any setting for cloud based log. The setting is obtained from user config file only.

inputToken is the token provided by loggly associated with an account.

subdomain is the name of the subdomain used to register an account.

logFolder

contains path to the log folder respective from the root folder. The logFolder value in the above config example is also the default value bound with the package.

Usage

Basically, it just needs to be imported in order to be used.

let log = require('winston-logger-setup');

log.cnsl('hello world!!');
log.error('Oh Snap!!');
log.warn('depreciated!!');
log.debug('Response needs modification');
log.info('Response successfully received');
log.cloud('IP:' + ip + ' connected');

log.cnsl is just the plain old log for console and doesn't get recorded to any file. log.cloud is for the cloud based log. The rest are for their obvious respective log files.

By default, all logs are of their respective levels i.e. log.error logs as an error level to the error.log file. But, in case we need to register an info level to the error.log file, we can use the following statement.

let log = require('winston-logger-setup');

log.errorLog.info("Oh snap!!");

It will be outputted as info log in console but will be recorded in the error.log file.

Similar for the other log levels. Cloud log has info level by default.

Author: Sujan Shrestha

Contributors: Sujan Shrestha