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

dush-logger

v1.2.2

Published

A file logger for Node.js apps

Downloads

29

Readme

DUSH-LOGGER

Easy, flexible, clean file logger for node

Installation

npm i dush-logger

npm install dush-logger

Documentation

Basic Use

const log = require('dush-logger');
let myVariable = true;

// Do Something
if (myVariable) {
  log.info('Variable `myVariable` is true');
} else {
  log.error('Variable `myVariable` is false');
}

Methods

log.<level>(message)

  • level {String} The level to log a message at
  • message {String} The log message

Enter a new log message

Examples


  
  // Below are the default log levels
  log.info('This is an info log message');
  log.notice('This is a notice log message');
  log.success('This is a success log message');
  log.warn('This is a warning log message');
  log.error('This is an error log message');
  log.debug('This is a debug log message');
  log.critical('This is is critical log message');
  log.verbose('This is a verbose log message');

log.createLevel(level, options)

  • level {String}
  • options {Object}
    • color: {String} Log level color(hex)
    • prefix: {String} String to be used as prefix of log message
    • file: {String} File path for the level

Create a new log level


// Create new level named server
log.createLevel('server', {prefix: 'SERV',color: '#28a745', file:'./logs/server.log'});

// Use the created level
log.server('New log messages under the server level');

log.clearLevel(level)

  • level {String}

NB : Set level to 'main' to clear the main or default log file

Deletes all the log messages previously written under the level.

// Clearing the log file for the info level
log.clearLevel('info');

log.deleteLevel(level)

  • level {String}

Deletes the log level ,any further attempt to use the level will result false and produce a message.

// Delete error level
log.deleteLevel('error');

// Trying to log a new message using the error level will result in an error
log.error('My new error log message');

log.viewLog(level)

  • level {String}

Outputs previously written log messages to the console and returns the messages as an array


log.viewLog('critical');

log.init(options)

  • options {Object}
    • file: {String} Set path for default log file
    • use_individual_files: {Boolean} true | false Set to true to write in level's independent files
    • levels: {Object} A showing level configurations including new levels
      • <level> {Object} Level configuration
        • color: {String} Log level color(hex)
        • prefix: {String} String to be used as prefix of log message
        • file: {String} File path for the level

Set options for log

/* Below are default options
{
file: './main.log',
use_individual_files: false,
dateFormat: 'nothing-yet',
levels: {
  info: {
    color:'#ffffff',
    prefix: 'INFO',
    file: 'logs/info.log'
  },
  debug: {
    color:'#1e7e34',
    prefix: 'DEBUG',
    file: 'logs/debug.log'
  },
  verbose: {
    color:'#28a745',
    prefix: 'VERBOSE',
    file: 'logs/verbose.log'
  },
  notice: {
    color:'#007bff',
    prefix: 'NOTICE',
    file: 'logs/notice.log'
  },
  success: {
    color:'#28a745',
    prefix: 'SUCCESS',
    file: 'logs/success.log'
  },
  warn: {
    color:'#ffc107',
    prefix: 'WARN',
    file: 'logs/warning.log'
  },
  error: {
    color:'#dc3545',
    prefix: 'ERROR',
    file: 'logs/error.log'
  },
  critical: {
    color:'#fd7e14',
    prefix: 'CRITIC',
    file: 'logs/critical.log'
  }
}*/

log.init({
    'use_individual_files': true,
    'levels': {
        'info': {
            'prefix': 'INFORMATION' 
        },
        'debug': {
            'prefix': 'DEBUGING',
            'file': './logs/debugger.log'
        }
    }
});

NB : Use the configuration file instead of log.init if you want to set override options across multiple files

log.setLogFile(level, file)

  • level {String}
  • file {String(path)}

Set the log file to be used for the level


log.setLogFile('info', './logs/info.log');

log.info('New info log message');

// The above log message will be written in the file ./logs/info.log instead of the default log file

Configuration File

Dush allows you to override default options using the dush configuration file. You simply create a dush-config.json file in the directory containing your node app file.

Example dush-config.json


{
  "use_individual_files": true,
  "levels": {
    "info": {
        "prefix": "INFORMATION"
    },
    "debug": {
        "prefix": "DEBUG",
        "file": "./logs/debug.log"
    }
  }
}