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

clrlog

v1.6.0

Published

Lightweight colorful JavaScript application logger with stack trace and logfile support for node.js

Downloads

30

Readme

#Clrlog# ##Lightweight colorful JavaScript application logger with stack trace and logfile support for node.js##

Build Status Dependency Status

Image

#Changes in version 1.6#

  • LOG_CUSTOM_VARIABLES allow tracing by also setting TRACE=true when debugging
  • Logging messages contain an ISO date string as default
  • Logging message type is always exposed [message], [success], [warning], [error]

#Changes in version 1.4#

##Log level changes##

  • Now the default log level is error & warning. Log message and success is disabled by default. It can be enabled again by setting the logLevel (logLevel='error,warning,success,message')

  • Any log message can be enabled temporary by

    • A) via process.env.DEBUG=true or
    • B) via context based environment variable which can be assigned to constructor

##Activation switch changes## Clrlog has now a new property inside the constructor. An env variable (process.env.CUSTOM_VARIALBE) can be registered (e.g by starting the node app CUSTOM_VARIALBE=true node app.js ) which enables any log level in the specific context for a better app behave logging.

#How to use# Instal Clrlog via npm

    npm install clrlog

Require the Clrlog class

    var Clrlog = require('clrlog');

To give log messages color set global.DEBUG=true or run application in node.js's debug mode

    process.env.DEBUG = true; // or on startup DEBUG=true node app.js

Or create a file named debug in applications root folder

Clrlog can be used as a function

    Clrlog("Hello I'm Clrlog");

Or as an object of the Clrlog class (The logger can be registered to a process.env property to enable logging for different purposes)

    var myClrlog = new Clrlog("I support logging into logfiles too", 'success', __dirname + '/application.log', 'MY_CUSTOM_LOG');
        myClrlog.logLevel = 'error';
        myClrlog.warning('This line is not written into logfile');
        myClrlog.error('This line is written into logfile');

Set custom log levels for a single logmessage type

    myClrlog.logLevel = 'error';

Or set log levels for multiple log message types

    myClrlog.logLevel = 'error,warning,success';

The logs are stored in the following format

    Sat Apr 05 2014 [...] | SUCCESS ᑀ And hold log instances for more complex logging purposes
    Sat Apr 05 2014 [...] | SUCCESS ᑀ The current loglevel is message,success
    Sat Apr 05 2014 [...] | MESSAGE ᑀ This message goes into the logfile
    Sat Apr 05 2014 [...] | SUCCESS ᑀ This line goes into the logfile too
    Sat Apr 05 2014 [...] | SUCCESS ᑀ {
    	"I": "can",
    	"log": "Objects too"
    }

#Full working example (demo/demo.js)#

    (function () {
        "use strict";

        // Enable global.DEBUG for colorful logging purposes
        // OR colorize logging when node is started in debug mode
        // global.DEBUG = true;
        //
        // A file named debug was created in applications root folder
        // so global.DEBUG is automatically set to true

        // Fetch Clrlog
        var Clrlog = require(__dirname + '/../index.js');

        ////////////////////////////////////////////////////////
        /////Call Clrlog like a plain old javascript funtion/////
        ////////////////////////////////////////////////////////

        Clrlog("Hello I'm Clrlog");
        Clrlog("I was successful", 'success');
        Clrlog("I've need to warn you ", 'warning');
        Clrlog("I've made a mistake", 'error');

        // Object Logging
        Clrlog({
            I: 'can',
            log: 'Objects too'
        }, 'success');


        // Save log messages in a file
        Clrlog("And I can store my logs into a file", 'message', __dirname + '/example.log');

        // Show stack trace behind logmessage
        Clrlog("My logs can also include a detailed stack trace", 'success', false, true);


        ////////////////////////////////////////////////////////
        /////Call Clrlog as an object for more comples stuff/////
        ////////////////////////////////////////////////////////

        var myClrlog = new Clrlog("And hold log instances for more complex logging purposes", 'success', __dirname + '/application.log');

        // LogLevel can be set on custom purposes
        myClrlog.logLevel = 'error';         // Only errormessages
        myClrlog.logLevel = 'warning';       // Only warnings
        myClrlog.logLevel = 'success';       // Only success
        myClrlog.logLevel = 'message';       // Only messages


        // Combined log levels are possble too
        myClrlog.logLevel = 'error,warning';
        myClrlog.logLevel = 'error,warning,success';
        myClrlog.logLevel = 'message,success';


        // Loglevel settings example
        myClrlog.logLevel = 'message,success';

        myClrlog.success('The current loglevel is ' + myClrlog.logLevel);

        myClrlog.message('This message goes into the logfile');
        myClrlog.error('This line is not written into logfile');
        myClrlog.success('This line goes into the logfile too');

    })();

Author: Clrlog was written by Bernhard Bezdek

Released under MIT License

###Dependencies### node.js file system api