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

logia

v1.0.4

Published

Flexible distributed logger module with hot-reload support

Downloads

31

Readme

NPM version downloads per month

logia


Flexible distributed logger module with hot-reload support

Features
  • Control loggers through configuration file during runtime without restarting your application (hot-reload).
  • Run both on the server and on the browser.
  • Master/slave mode support which allows logger orchestration in distributed systems
  • RegExp configuration matchers
  • Colored logs
  • Log file size limiters
  • Remote logging through websockets or http

Install

Install with npm:

$ npm install logia

Use

const Logia = require("logia");
const dbLogger = Logia("database");
const parserLogger = Logia("parser");

dbLogger.setLevel("trace");
parserLogger.setLevel("debug");

dbLogger.trace("Number of entries are 0.");
parserLogger.debug("Invoked with no arguments.");
dbLogger.info("Retrieving data...");
parserLogger.warn("Note that something is missing!");
dbLogger.error("Something exploded!");
parserLogger.fatal("something went terribly wrong :(");

Above code will give below output:

(31-03-2017 11:54:06) TRACE [database]:Number of entries are 0.
(31-03-2017 11:54:06) DEBUG [parser]  :Invoked with no arguments.
(31-03-2017 11:54:06) INFO  [database]:Retrieving data...
(31-03-2017 11:54:06) WARN  [parser]  :Note that something is missing!
(31-03-2017 11:54:06) ERROR [database]:Something exploded!
(31-03-2017 11:54:06) FATAL [parser]  :something went terribly wrong :(

Logs can also be parameterized

const pi = 3.14;
const e = 2.72;

logger.info("Value of 'pi' is '{0}' and value of 'e' is '{1}'", pi, e);

Configuration File

When requiring the logia module a logia.json configuration file is created under a config folder of the current working directory. Alternatively we can set the LOGIA_CONFIG_FILE_PATH environment variable if we want to change the default configuration filename and location.

Every change we make in the configuration file is immediately applied to the configuration of the loggers without the need of rebooting our application

{
    "level": {
        ".*": null
    },
    "appenders": {
        "$_fill_logger_name_regexp": {
            "filepath": null,
            "maxSize": null
        }
    },
    "remotes": {
        "$_fill_logger_name_regexp": {
            "protocol": null,
            "url": null
        }
    },
    "mode": {
        "type": null,
        "host": null,
        "port": null
    },
    "stdout": false,
    "dateFormat": "(DD-MM-YYYY HH:mm:ss)",
    "overwritable": true
}

level

In this section we can set the logging level of our loggers. We target loggers by writing a javascript regexp string which matches the name of the loggers and set its level.

For example, below configuration will set all loggers that start with the substring "database" to level info and all loggers that contain the substring "handler" to level error;

 "level": {
    "^database": "info",
    "*handler": "error"
  }

By setting the level of a logger we also activate the logger and we enable others features(e.g appenders, remotes) to further configure them.

appenders

In the appenders section we can define where the logs will be stored in our filesystem. We target the loggers by writing a javascript regexp string, the same way we did for the level section but instead for setting the logging level we specify the output file. Moreover we can set the maxSize property in which we specify the maximum size in MBs of the log file. If the size of that file reaches the specified limit then the first half of its contents will be deleted. The filepath is treated as an absolute path unless it starts with ./ which then is resolved as a relative path to the current working directory.

For example, below configuration will append the logs of the loggers which name starts with the "database-mongo" and "database-redis" substring to the "/temp/redis.log" and "/temp/mongo.log" files respectively and limit their size to 20MBs. Similarly, the logs of the loggers which contain the "handler" substring in their name will end up in "cwd/logs/handler-errors.log" file.

 "appenders": {
    "^database-mongo": {
        "filepath": "/temp/mongo.log",
        "maxSize": 20
    },
     "^database-redis": {
        "filepath": "/temp/redis.log",
        "maxSize": 20
    },
    "*handler": {
        "filepath": "./logs/handler-errors.log"
    }
  }

remotes

The remotes section is similar to the appenders section but instead of appending the logs in a file it allows us to send them in a remote location. We need to provide a destination url and a protocol. Supported protocols are ws(websockets) and http and both use JSON format.

For example, below configuration will send the logs of the loggers which name starts with the "database" substring to the websocket server that runs on "websocket.server.com:8989". Similarly, the logs of loggers with the "handler" substring in their name will be send to the http server that runs on "http.server.com:8080".

 "remotes": {
    "^database": {
        "url": "websocket.server.com:8989",
        "protocol": "ws"
    },
    "*handler": {
        "url": "http.server.com:8080",
        "protocol": "http"
    }
  }

mode

Logia can run both as a master or as a slave node.

master

Below configuration will boot up a master node on localhost:8080.

  "mode": {
        "type": "master",
        "host": "master.server.com",
        "port": 8080
    }

By running a logia instance as a master node it allows to control all connected slaves through the masters node configuration file.

slave

Below configuration will boot up a slave node that will be connected and controlled by the the master node specified above.

  "mode": {
        "type": "slave",
        "host": "master.server.com",
        "port": 8080
    }

The master/slave setup uses websockets which preserves the order of the logs. This enables us to gather logs for client-server applications and still read them from top to bottom without the need of applying any type of sorting.

stdout

By setting this properrty to true all logs will be printed in standard output.

dateFormat

Set the date format. Uses Moment.js display format.

overwritable

See Logia.overwriteConfigFile

API

All aforementioned features are also accesible through a programming interface. Check the API documentation in Markdown or HTML

License

Copyright (c) 2016 Ioannis Tzanellis Released under the MIT license