1.0.3 • Published 9 years ago
anywhere-log v1.0.3
Anywhere-log
What?
Straight-forward logging module.
- lines up everything in nice columns
- uses colors
- sends everything straight to
process.stderr(no events, nonextTick()) if desired - condenses repeated messages
- displays stack traces for logged Error instances and other multi-line content nicely
- optionally displays the source of the logging call
- supports wrapping of morgan in your express app
- can replace the debug module, using hartwig-at/debug
Example
var log = require( "anywhere-log" ).module( "demo" );
log.info( "Logging without source tracing" );
log.notice( "Initializing application...\nwow\nsuch application" );
log.critical( new Error( "Logging an Error instance." ) );
log.withSource();
log.info( "Logging WITH source tracing" );
log.notice( "You'll never know where this was logged from!" );
log = require( "anywhere-log" );
log.warn( "We don't need no prefix!" );
log = require( "anywhere-log" ).module( "something weird" );
log.warn( "...or do we?" );
log = require( "anywhere-log" );
log.notice( "You're using a longer prefix? I'll adjust." );
log = require( "anywhere-log" ).module();
log.error( "ouch" );// Wrap morgan
app.use( require( "anywhere-log" ).module( "HTTP" ).morgan( {format : "dev"} ) );How?
Install
npm install anywhere-log -SPut this in every file where you want to log:
var log = require( "anywhere-log" ).module();Then just use log.info or one of the other logging levels shown above.
For loggers without a specific prefix, just require() the module and use it directly:
var generic = require( "anywhere-log" );
generic.notice( "We don't need no prefix" );To log to a different stream (process.stdout is the default), use .to():
var logger = require( "anywhere-log" ).to( process.stderr );To send data straight to the output stream (without nextTick()), use .sync():
var logger = require( "anywhere-log" ).sync();Using Papertrail
const logger = require('./lib').ptLog;
const pt = logger.pt(host, port);
const l = logger.create([pt]);
l.info('hello log');
l.info('logging before I close');
pt.on('connect', () => {
setTimeout(() => l.close(), 500);
});