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

meta-logger

v1.0.4

Published

Light logging library for NodeJS

Downloads

15

Readme

meta-logger

Lightweight logging library for NodeJS with support of facilities and multiple transports.

Usage

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

//Setup targets
logger.toConsole({
	level: "debug",
	timestamp: true,
	colorize: true
}).toFile("demo.log", {
	level: "info",
	timestamp: true,
	facilities: [ "test" ]
}).toJsonFile("demo.json", {
	level: "warn"
});

//Logging without specifying facility
logger.log("info", "Hello %s", "world");
logger.debug("Hello %s", "debug");
logger.info("Hello %s", "info");
logger.warn("Hello %s", "warn");
logger.error("Hello %s", "error");

//Create facility shorthand
var facilityLogger = logger.facility("test");

//Log with facility prefix
facilityLogger.log("info", "Hello %s", "world");
facilityLogger.debug("Hello %s", "debug");
facilityLogger.info("Hello %s", "info");
facilityLogger.warn("Hello %s", "warn");
facilityLogger.error("Hello %s", "error");

Note: console target is set by default.

Configuring logging targets

Console

Prints log messages to stdout (console).

logger.toConsole({
	level: "debug",
	facilities: [...], //or null to accept all facilities
	timestamp: true,
	colorize: true,
	colors: {
		debug: 	logger.colors.cyan,
		info: 	logger.colors.white,
		warn: 	logger.colors.yellow,
		error: 	logger.colors.red
	}
});

Method toConsole overrides previous console target settings. You can use more console targets (for multiple configurations):

logger.to(new Logger.ConsoleTarget({
	///... options ...
}));

File

Append log messages to specified file.

Message is formatted same way as to console.

File target can be set for multiple files with different configurations.

logger.toFile(filename, {
	level: "debug",
	facilities: [...], //or null to accept all facilities
	timestamp: true
}).toFile(anotherFilename, {
	level: "error",
	timestamp: true,
	//...
});

JSON file

Append log messages to specified file in JSON format.

logger.toJsonFile(filename, {
	level: "debug",
	facilities: [...], //or null to accept all facilities
	timestamp: true
});

Log file has following format:

{},
{"timestamp":"2015-06-04T21:20:54.627Z","level":"warn","facility":null,"msg":["Hello %s","warn"]},
{"timestamp":"2015-06-04T21:20:54.629Z","level":"error","facility":"test","msg":["Hello %s","error"]}
...

Custom logging target

Custom target is defined by instance of simple object which implements log method and registered to logger via to method.

Following example shows how to define custom target:

var util = require("util");

var MyTarget = function(options){

	options = options || {};
	this.prefix = options.prefix || "";

};

MyTarget.prototype.log = function(level, facility, args){

	console.log(level, facility, this.prefix, util.format.apply(this, args));

};

logger.to(new MyTarget({
	prefix: "my-target"
}));

Following example shows how to inherit BaseTarget:

var MyTarget = function(options){

	options = options || {};
	this.prefix = options.prefix || "";

	logger.BaseTarget.call(this, options);

};

util.inherits(MyTarget, logger.BaseTarget);

MyLogger.prototype.write = function(level, facility, msg){

	console.log(level, facility, this.prefix, msg.join(" "));

};

Custom logging levels

Logging levels can be set by modifying logger.levels property.

logger.levels = {
	custom: 4,
	debug: 	3,
	info: 	2,
	warn: 	1,
	error: 	0
};

Logger object reference

logger = {

	//Colors library for console coloring
	colors: require("colors"),

	//Logging levels
	levels: {
		debug: 	3,
		info: 	2,
		warn: 	1,
		error: 	0
	},

	//Object contains registered targets
	targets: {},

	//Logging functions
	log: function(level, args...),
	debug: function(args...),
	info: function(args...),
	warn: function(args...),
	error: function(args...),

	//Facility shorthand
	facility: function(name){

		return {

			log: function(level, args...),
			debug: function(args...),
			info: function(args...),
			warn: function(args...),
			error: function(args...)

		};

	},

	//Target shorthands
	to: function(name, targetObject),
	toConsole: function(options),
	toFile: function(filename, options),
	toJsonFile: function(filename, options),

	//Target constructors
	BaseTarget: function(options),
	ConsoleTarget: function(options),
	FileTarget: function(filename, options),
	JsonFileTarget: function(filename, options)

};

License

This library is published under MIT license.

Copyright (c) 2015 Jiri Hybek, [email protected]