2.0.0 • Published 8 years ago

logwrangler v2.0.0

Weekly downloads
15
License
MIT
Repository
github
Last release
8 years ago

logwrangler is a module logging system that you can easily extend to add various logging locations and functions.

Install

npm install --save logwrangler

Use

Logging to stdout

var logwrangler = require('../index');
var logger = logwrangler.create();

logger.log({
	level: logger.levels.INFO,
	ns: 'web server',
	message: 'some log message',
	data: {}
});

Options

level <string>

Specifies the level of the log. Levels can be found in logwrangler object or in the logger instance object.

Available levels include:

  • DEBUG
  • INFO
  • WARN
  • ERROR

ns <string>

Specifies a particular namespace for your log. Good for grouping logs by location in your codebase or by component.

node <string>

Name of the node, machine, or specific process currently running.

ident <string>

A more local identifier for the particular log. This could be something like a user ID to make it easy to trace the actions of a user.

message <string>

A human readable message to describe what is happening

data <object>

Contextual data related to the this particular log message. If the value of data is an Error(), the error will be parsed to grab it's message and stack trace and data will be rewritten to have an error property that will contain the contents of the Error object.

data, no error

{
	data: {
		someKey: 'someValue'
	}
}

data, with error

{
	data: new Error('Some error message')
}

// will become:

{
	data: {
		error: {
			message: 'Some error message',
			stack: <stack trace>
		}
	}
}

data, error and context

{
	data: {
		error: new Error('Some error message'),
		someKey: 'someValue'
	}
}

// will become

{
	data: {
		error: {
			message: 'Some error message',
			stack: <stack trace>
		},
		someKey: 'someValue'
	}
}

Custom logging handler

Creating a custom logger is as easy as providing an anonymous function to logger.use.

Parameters

options

Options that you passed in during initialization

	{
		options: {
			level: <level to use>
		}
	}

data

The data to be logged

{
	data: {
		level: <log level>,
		ns: <namespace - string>,
		ident: <custom identifier - string>,
		node: <node, machine, process, identifier - string>
		message: <message - string>,
		data: <custom data - object>
	}
}

Usage

var logger = fancyLog.create({
	level: fancyLog.levels.DEBUG, // default level to log
});

logger.use(function(options, data){
	
	// do something with your data
});
2.0.0

8 years ago

1.0.0

9 years ago

0.1.5

10 years ago

0.1.4

10 years ago

0.1.3

10 years ago

0.1.2

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago

0.0.9

10 years ago

0.0.8

10 years ago

0.0.6

10 years ago

0.0.5

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago