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

solid-logger-js

v1.3.2

Published

solid-logger-js is a project that will create logs in a consistant way between your projects. There are a ton of options when implementing logging in your application. The solid-logger series implements the same tasks across programming languages. The ide

Downloads

52

Readme

___________________________________
__  ___/_  __ \__  /____  _/__  __ \
_____ \_  / / /_  /  __  / __  / / /
____/ // /_/ /_  /____/ /  _  /_/ /
/____/ \____/ /_____/___/  /_____/

______ ________________________________________                ________________
___  / __  __ \_  ____/_  ____/__  ____/__  __ \               ______  /_  ___/
__  /  _  / / /  / __ _  / __ __  __/  __  /_/ /  ________     ___ _  /_____ \
_  /___/ /_/ // /_/ / / /_/ / _  /___  _  _, _/   _/_____/     / /_/ / ____/ /
/_____/\____/ \____/  \____/  /_____/  /_/ |_|                 \____/  /____/

Build Status

What am I?

solid-logger-js is a project that will create logs in a consistent way between your projects. There are a ton of options when implementing logging in your application. The solid-logger series implements the same tasks across programming languages. The idea is that logging in node projects is identical to php, ruby, etc.

Features

  • Handles logging objects

  • Handles circular references

  • Handles logging Errors

  • Asynchronous

  • Built in Console adapter with colors

  • Built in File adapter with day based log rotation

  • Built in Loggly adapter

  • Save multiple messages like console.log

  • Customizable - just push your own adapter on:

    var logger = require('solid-logger-js').init();
    
    logger.adapters.push(myCustomAdapter);
    
    // The adapter should do the desired behavior when it is called with adapter.write(type, category, message)
    // The adapter should return a Bluebird promise that is resolved when the work is done

Dependencies

Node 4+

Why do you want to use me?

Logging is crucially important and necessary for all applications. If a standard practice is not adopted then each team will implement their own way of doing it. Solid logger will not only log to a file, but you can implement adapters that will save data to other databases or to the cloud. The API can also act as a gateway to present the logs in various ways through a web interface (separate project).

How can I be made more useful?

If you want to contribute to this project you could add in more adapters for different output types or implement a new language that uses the same interface and configurations (so that we maintain a consistant feel).

Methods

  • trace
  • debug
  • write
  • warn
  • error
  • critical

Config

The logger needs to be configured before it is used. This is done by calling the init method after requiring the logger.

var logger = require('solid-logger-js');

logger.init({
    adapters: [{
        type: "file",
        path: path.resolve(__dirname, "../") + "/log/grasshopper-api.log",
        application: 'grasshopper-api',
        machine: 'dev-server'
    },{
             type: "file",
             path: "/your/full/path/log/backup-test.log",
             application: 'grasshopper-api',
             machine: 'dev-server'
    }]
});

Filters

Sometimes you don't want to save everything that is logged. Some environments don't need all the data. So there is a filter configuration that can be used PER ADAPTER. So if you want everything logged to the console but only certain things logged to a file or remotely, then no problem. The following Example shows everything in the console but filters out trace, info and debug entries to the file.

logger = Logger.init({
    adapters: [{
            type: 'console',
            application: 'grasshopper-api',
            machine: 'dev-server'
        },{
            type: 'file',
            path: path.join(__dirname, '..', '..', 'log', 'std.out.log'),
            application: 'grasshopper-api',
            machine: 'dev-server',
            filter: ['trace','info','debug']
        }]
});

There are a couple of other ways you can configure the module.

Inline

var logger = require('solid-logger-js').init({
    adapters: [{
        type: "file",
        path: path.resolve(__dirname, "../") + "/log/grasshopper-api.log",
        application: 'grasshopper-api',
        machine: 'dev-server'
    }]
});

With a configuration file

var logger = require('solid-logger-js').initWithFile("/path/to/your/file");

Usage

After you configure your logger, then you can easily call it like:

logger.debug('Useful Label', 'This is my debugging message.');

It will automatcially write to all of your defined adapters.

Adapters

  • file
  • console
  • loggly
  • remote
  • callback

File

The file adapter will expect the type set to file and then a path to a log file.

{
    type: "file",
    path: path.resolve("./log/test.log"),
    application: 'grasshopper-api',
    machine: 'dev-server'
}

NOTE: Files are split daily so the file path is used for the current day but then it is archived by date.


Console

The console adapter will expect the type set to console.

{
    type: "console",
    application: 'grasshopper-api',
    machine: 'dev-server'
}

Loggly

Loggly is a popular cloud-based log management service. http://loggly.com

The loggly adapter will expect the type set to loggly.

{
    type: "loggly",
    application: "grasshopper-api",
    machine: "dev-server",
    token: "loggly token",
    domain: "website url",
    auth: {
        username: "",
        password: ""
    }
}

Remote

Sends parameterized GET requests to a remote endpoint, or sends POST requests with json data. You can optionally configure any desired headers as an object in the config.

logger = Logger.init({
    adapters: [
        {
            type: 'remote',
            verb: 'GET',
            url: 'http://localhost:4321/log',
            application: 'test',
            machine: 'test-host',
            headers : {
                'x-api-key' : 'abcdefg',
                'something' : 'else'
            }
        }
    ]
});

Supported verbs: GET, POST


Callback

Pass in a callback that gets called with the entry object.

var logger = Logger.init({
    adapters: [{
        type: 'callback',
        application: 'logger1',
        machine: 'staging',
        callback: function(entryOjbect) { ... }
    }]
});