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

cinovo-logger

v0.4.12

Published

Async logger for Node.js with multiple endpoints.

Downloads

15

Readme

                                                   ___
       __                                         /\_ \
  ___ /\_\    ___     ___   __  __    ___         \//\ \     ___      __      __      __   _ __
 /'___\/\ \ /' _ `\  / __`\/\ \/\ \  / __`\  _______\ \ \   / __`\  /'_ `\  /'_ `\  /'__`\/\`'__\
/\ \__/\ \ \/\ \/\ \/\ \L\ \ \ \_/ |/\ \L\ \/\______\\_\ \_/\ \L\ \/\ \L\ \/\ \L\ \/\  __/\ \ \/
\ \____\\ \_\ \_\ \_\ \____/\ \___/ \ \____/\/______//\____\ \____/\ \____ \ \____ \ \____\\ \_\
 \/____/ \/_/\/_/\/_/\/___/  \/__/   \/___/          \/____/\/___/  \/___L\ \/___L\ \/____/ \/_/
                                                                      /\____/ /\____/
                                                                      \_/__/  \_/__/

Build Status NPM version NPM dependencies

cinovo-logger

cinovo-logger is an async logger for Node.js with multiple endpoints.

Getting started

At first you must install and require the logger.

npm install cinovo-logger

Next you must require the module

var logger = require("cinovo-logger");

Append an endpoint

There are some endpoints available:

You could also write your own endpoint (see Custom Endpoint).

If you wish to log to console just:

npm install cinovo-logger-console

In your JavaScript code append the endpoint.

logger.append(require("cinovo-logger-console")(true, true, true, true));

If you wish to log to syslog just:

npm install cinovo-logger-syslog

In your JavaScript code append the endpoint.

logger.append(require("cinovo-logger-syslog").local(true, true, true, true, "test", "local0"));

You could also log to file, AWS (S3, SQS, SNS), Mac OS X Notification Center or Loggly

Log something

logger.debug("all values are ok");
logger.info("myscript", "all values are ok");
logger.error("myscript", "some values are not ok", {a: 10, b: 20});
logger.exception("myscript", "some values are not ok", new Error("error"));
logger.critical("myscript", "all values are not ok", {a: 10, b: 20}, function(err) { ... });

Done

Now you can log to multiple endpoints.

Integrate

You are likely to use some other npms so we tried to integrate cinovo-logger with some popular npms by providing wrapprs:

API

debug, info, error, critical([origin], message, [metadata], [callback])

Depending on the level you want to log choose one of the four methods.

  • origin: String to indicate where the log come from, e. g. the name of the script (optional)
  • message: String to tell what happened
  • metadata: String, Number, Boolean, Array or Object to tell you more about the situation (optional)
  • callback: Function(err) Fired after log was processed by all endpoints (optional)
    • err: Error (optional)

Examples:

logger.debug("all values are ok");
logger.info("myscript", "all values are ok");
logger.error("myscript", "some values are not ok", {a: 10, b: 20});
logger.critical("myscript", "all values are not ok", {a: 10, b: 20}, function(err) { ... });

exception([origin], message, error, [callback])

If you want to log an Error there is a special method exception which logs as an error

  • origin: String to indicate where the log come from, e. g. the name of the script (optional)
  • message: String to tell what happened
  • error: Error
  • callback: Function(err) Fired after log was processed by all endpoints (optional)
    • err: Error (optional)

Examples:

logger.exception("some values are not ok", new Error("error"));
logger.exception("myscript", "some values are not ok", new Error("error"));
logger.exception("myscript", "some values are not ok", new Error("error"), function(err) { ... });

Log

The log object contains the following fields:

{
	level: String["debug", "info", "error", "critical"]
	date: Date
	pid: Number
	hostname: String
	origin: String to indicate where the log come from, e. g. the name of the script (optional)
	message: String to tell what happened
	metadata: String, Number, Boolean, Array or Object to tell you more about the situation (optional)
	fullOrigin: {
		file: String of the file name,
		line: Number of the line,
		fn: String of the invoked function name
	} (optional)
}

EventEmitter

The cinovo-logger is also an EventEmitter.

on, addListener(event, listener)

Adds a listener to the end of the listeners array for the specified event.

  • event: String
  • listener: Function - see Events for signature

once(event, listener)

Adds a one time listener for the event. This listener is invoked only the next time the level is fired, after which it is removed.

  • event: String
  • listener: Function - see Events for signature

removeListener(event, listener)

Remove a listener from the listener array for the specified event.

  • event: String
  • listener: Function - see Events for signature

removeAllListeners([event])

Removes all listeners, or those of the specified event.

  • event: String (optional)

append(endpoint)

  • endpoint: must extend Endpoint see Custom Endpoint

remove(endpoint, callback)

  • endpoint: must extend Endpoint see Custom Endpoint
  • callback: Function(err)
    • err: Error

stop(callback)

Stop all endpoints to avoid data loss.

  • callback: Function(err)
    • err: Error

fullOrigin()

Activates fullOrigin output in log. Locates the caller of an log function debug, info, error, exception, critical by:

{
	file: String of the file name,
	line: Number of the line,
	fn: String of the invoked function name
}

Events

level_debug(log)

On debug log.

  • log: Log

level_info(log)

On info log.

  • log: Log

level_error(log)

On error log.

  • log: Log

level_critical(log)

On critical log.

  • log: Log

error(err)

If you use on of the log methods debug, info, error, exception, critical without the optional callback and an Error occurs it is emitted.

  • err: Error

endpoint_error(endpoint, err)

If an endpoint.log() returned an error or an error was emitted by an endpoint.

  • endpoint: Endpoint
  • err: Error

Advanced Stuff

Multiple logger instances

From time to time it makes sense to have more than one logger instance.

var myLogger = require("cinovo-logger").createLogger();

myLogger.append(require("cinovo-logger-console")(true, true, true, true));

myLogger.debug("all values are ok");

Configuration

You can configure the logger during creation or after creation.

during creation:

var cfg = {
	fullOrigin: false,
	filter: {
		"*": true
	}
};
var myLogger = require("cinovo-logger").createLogger(cfg);

after creation:

var logger = require("cinovo-logger");
// do something
logger.cfg.fullOrigin = true;

Options

There are several options available:

fullOrigin

Boolean - Activates fullOrigin output in log. (default: false)

Examples:

var cfg = {
	fullOrigin: true
};
filter

Object - Allow or block log from origin and/or level. (default: {"*": true})

Examples:

`````javascriptvar cfg = { filter: { "*": false, // block everything (required) "*/critical": true, // but allow criticallevel "myorigin/*": true, // and allow everything fromoriginmyorigin "yourorigin/debug": true, // and allow everything fromoriginyourorigin andlevel` debug } };


### Custom Endpoint

Visit [cinovo-logger-lib](https://github.com/cinovo/node-logger-lib).