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

perfect-logger

v2.1.0

Published

A customizable logger that can be used with NodeJS application for terminal logging purposes

Downloads

306

Readme

perfect-logger

FOSSA Status

The Perfect-Logger library exported as Node.js modules. With Perfect-Logger you can improve your application's logs

License

FOSSA Status

Highlights

  • Easy to use
  • Configurable
  • Write log events to file
  • Automatic log switching to avoid huge log files
  • Custom log codes with log levels
  • Log event call back support
  • Colored terminal output

Installation

Using npm:

npm i perfect-logger

In Node.JS

// Load the perfect-logger module
let logger = require('perfect-logger');

// Configure Settings
logger.initialize('FrontEndDriver', {
    logLevelFile: 0,                    // Log level for file
    logLevelConsole: 0,                 // Log level for STDOUT/STDERR
    logDirectory: 'logs/',              // Log directory
    customBannerHeaders: 'This is a custom banner'  // Custom Log Banner
});

// Use
logger.info("This is an information");
logger.warn("This is a warning");
logger.crit("This is a critical message");
logger.debug('Wassup', {eyes: 2, feet: 2, hands: 2, eyeColor: 'blue'});
logger.info('Wassup', {eyes: 2, feet: 2, hands: 2, eyeColor: 'blue'});
logger.warn('Wassup', {eyes: 2, feet: 2, hands: 2, eyeColor: 'blue'});
logger.crit('Wassup', {eyes: 2, feet: 2, hands: 2, eyeColor: 'blue'});

Sample Terminal Output

 2020/02/21 | 18:26:00 | INFO | This is an information 
 2020/02/21 | 18:26:00 | WARN | This is a warning 
 2020/02/21 | 18:26:00 | CRIT | This is a critical message 
 2020/02/21 | 18:26:00 | DEBUG | Wassup 
 2020/02/21 | 18:26:00 | INFO | Wassup 
 2020/02/21 | 18:26:00 | WARN | Wassup 
 2020/02/21 | 18:26:00 | CRIT | Wassup

Sample Log File

***************************************************************************************************
*** 
*** This is a custom banner
*** 
***************************************************************************************************
*** 
*** Module Name          : FrontEndDriver
*** Project Name         : perfect-logger
*** Version              : 1.6.1
*** Configured Timezone  : Asia/Colombo
*** 
***************************************************************************************************
*** 
*** Log Number           : #1
*** Process Start Time   : 2/21/2020, 6:28:33 PM
*** Log Start Time       : 2/21/2020, 6:28:33 PM
*** Log Level            : 0
*** Continuing From      : None
*** 
***************************************************************************************************
*** 
*** Hostname             : XS3
*** OS Release           : 4.15.0-50-generic
*** Platform             : linux
*** NodeJS Version       : 8.17.0
*** OpenSSL Version      : 1.0.2s
*** 
***************************************************************************************************
*** 
*** DEPENDENT NPM PACKAGE DETAILS
*** 
*** [email protected] /home/sulochana/Documents/perfect-logger
*** ├── [email protected]
*** ├── [email protected]
*** ├── [email protected]
*** ├── [email protected]
*** └── [email protected]
*** 
*** 
***************************************************************************************************
2020/02/21 | 18:28:35 | INFO | This is an information
2020/02/21 | 18:28:35 | WARN | This is a warning
2020/02/21 | 18:28:35 | CRIT | This is a critical message
2020/02/21 | 18:28:35 | DEBUG | Wassup
[61]~ {
[61]~     "eyes": 2,
[61]~     "feet": 2,
[61]~     "hands": 2,
[61]~     "eyeColor": "blue"
[61]~ }
2020/02/21 | 18:28:35 | INFO | Wassup
[BQ]~ {
[BQ]~     "eyes": 2,
[BQ]~     "feet": 2,
[BQ]~     "hands": 2,
[BQ]~     "eyeColor": "blue"
[BQ]~ }
2020/02/21 | 18:28:35 | WARN | Wassup
[A8]~ {
[A8]~     "eyes": 2,
[A8]~     "feet": 2,
[A8]~     "hands": 2,
[A8]~     "eyeColor": "blue"
[A8]~ }
2020/02/21 | 18:28:35 | CRIT | Wassup
[KQ]~ {
[KQ]~     "eyes": 2,
[KQ]~     "feet": 2,
[KQ]~     "hands": 2,
[KQ]~     "eyeColor": "blue"
[KQ]~ }

Configuration Options

Configuration options needs to passed during the initialization. All these options are optional. Example

logger.initialize('ApplicationName', {
    logLevelFile: 0,                    // Log level for file
    logLevelConsole: 0,                 // Log level for STDOUT/STDERR
    logDirectory: 'logs/',              // Log directory
    customBannerHeaders: 'This is a custom banner'  // Custom Log Banner
});

Log Level

Log levels margins are as follow. You may declare your own log codes within the range -1 <= logLevel <= 10

DISABLED: -1
DEBUG: 0
INFO: 4
WARNING: 8
CRITICAL: 10

Log File

The log file will be saved as <ApplicationName>.log in the current working directory. Any existing log file with the same name will be renamed to following format <ApplicationName>.<ProcessID>.<ProcessStartTime>.log. Therefore the log file of the currently running process is always <ApplicationName>.log. You can change the log directory using the following option

logDirectory: './ApplicationLogs'

Sets the log level for the file output. The default value is 0 (LOG_LEVEL_DEBUG). Setting log level to -1 or any negative number will disable the log file.

logLevelFile: 0

Setting a maximum log file size will allow you to switch to new log file when the file size limit is reached. This is usefull to split log files. You must provide the size limit in Bytes.

maximumLogFieSize: 102400000

You can add a custom banner to log file

customBannerHeaders: 'This is a custom banner'

Console Log

Set the log level for the console output. The default value is 4 (LOG_LEVEL_INFO). Setting log level to -1 or any negative number will disable the console output.

logLevelConsole: 0

Callback

You can set a callback function whenever a log event is fired. This callback function should accept on parameter.

function myCallbackFunction(obj) {
    console.log('CALLBACK OUTPUT:', obj);
}

logger.initialize('FrontEndDriver', {
    callbackLogEvent: myCallbackFunction
});

The object passed into the function will be in following example format

{
    alias: 'info',
    message: 'Sample log message',
    code: 'INFO',
    color: 'red',
    logLevel: 4,
    time: '20:05:49',
    date: '2020/02/21',
    object: {}
}

Set the log level for the callback. The default value is 0 (LOG_LEVEL_DEBUG). Setting log level to -1 or any negative number will disable the callback.

logLevelCallback: 0

Timezone

You can change the logging timezone with the following option. Default timezone is UTC You can find a list of TimeZones here : https://timezonedb.com/time-zones

timezone: 'Asia/Colombo'

Development Mode

You can enable development with the following option. This will maintain a single log file.

developmentMode: true

Help and Support

For any queries drop an email to [email protected]