log-driver

WebJar for log-driver

License

License

ISC
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

log-driver
Last Version

Last Version

1.2.7
Release Date

Release Date

Type

Type

jar
Description

Description

log-driver
WebJar for log-driver
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/cainus/logdriver

Download log-driver

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/log-driver/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>log-driver</artifactId>
    <version>1.2.7</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/log-driver/
implementation 'org.webjars.npm:log-driver:1.2.7'
// https://jarcasting.com/artifacts/org.webjars.npm/log-driver/
implementation ("org.webjars.npm:log-driver:1.2.7")
'org.webjars.npm:log-driver:jar:1.2.7'
<dependency org="org.webjars.npm" name="log-driver" rev="1.2.7">
  <artifact name="log-driver" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='log-driver', version='1.2.7')
)
libraryDependencies += "org.webjars.npm" % "log-driver" % "1.2.7"
[org.webjars.npm/log-driver "1.2.7"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

There are no modules declared in this project.

Log Driver

Build Status NPM Version codecov.io

Logdriver is a node.js logger that only logs to stdout.

You're going to want to log the output of stdout and stderr anyway, so you might as well put all your logging through stdout. Logging libraries that don't write to stdout or stderr are missing absolutely critical output like the stack trace if/when your app dies.

There are some other nice advantages:

  • When working on your app locally, logs just show up in stdout just like if you'd used console.log(). That's a heck of a lot simpler than tailing a log file.
  • Logging transports can be externalized from your app entirely, and completely decoupled. This means if you want to log to irc, you write an irc client script that reads from stdin, and you just pipe your app's output to that script.
node yourapp.js 2>&1 | node ircloggerbot.js 
  • You can still easily log to a file on a production server by piping your stdout and stderr to a file like so when you initialize your app:
node yourapp.js 2>&1 >> somefile.log 

NB: If you're logging to a file, Logrotate is probably going to be your best friend.

  • You can still easily log to syslog by piping your stdout and stderr to the 'logger' command like so:
node yourapp.js 2>&1 | logger

Usage:

Getting the default logger:

var logger = require('log-driver').logger;

This logger has levels 'error', 'warn', 'info', 'debug', and 'trace'. If you don't like those levels, change the default:

var logger = require('log-driver')({
  levels: ['superimportant', 'checkthisout', 'whocares' ]
});
logger.whocares("brangelina in lover's quarrel!");

Specifying what log level to log at to make logs less chatty:

var logger = require('log-driver')({ level: "info" });
logger.info("info test"); 
logger.warn("warn test"); 
logger.error("error test"); 
logger.trace("trace test"); 

output:

[info] "2013-03-26T18:30:14.570Z"  'info test'
[warn] "2013-03-26T18:30:14.573Z"  'warn test'
[error] "2013-03-26T18:30:14.574Z"  'error test'

(notice the trace() call was omitted because it's less than the info level.

Turning off all log output (sometimes nice for automated tests to keep output clean):

var logger = require('log-driver')({ level: false });

Using the same logger everywhere: The last logger you created is always available this way:

var logger = require('log-driver').logger;

This way, if you use only one logger in your application (like most applications), you can just configure it once, and get it this way everywhere else.

Don't like the logging format? Just change it by passing a new formatting function like so:

var logger = require('log-driver')({ 
  format: function() {
    // let's do pure JSON:
    return JSON.stringify(arguments);
  }
});

Versions

Version
1.2.7
1.2.4