log4njs
A very simple log utility for nodejs
Last updated 10 months ago by polythene .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install log4njs 
SYNC missed versions from official npm registry.

log4njs

log4njs is a very simple log utility for nodejs.

Build Status npm version Coverage Status

Installation

npm i log4njs --save

Migration to 2.0.0

See CHANGELOG for breaking changes.

Default usage

$ const log = require('log4njs')();
$ log.info('Hello world', { foo: 'bar' });
> '[INFO] Hello world' { foo: 'bar' }

API

Options

  • level: String or int. The log level of the logger instance. Defaults to INFO (300).
  • prefix: String. An optional string that is prefixed to all log messages. Default to ''.
  • timestamp: Boolean. Indicate if the log messages should include the current timestamp (YYYY-MM-DDTHH:mm:ss:mmmZ). Defaults to false.

Setting the environment variable LOG_LEVEL will initiate the logger with the provided setting. If log level is not provided it is set to INFO.

Example

const log = require('log4njs')({ level: 'DEBUG', prefix: 'MyPrefix::', timstamp: true });

Suppress logs

In unit tests, for example, you may want to suppress all log statements:

$ LOG_LEVEL=suppress npm test

Audit Logging

There are two Audit log level, introduced in 2.1.0.: AUDIT & AUDIT_ALERT. They can only be turned off by suppressing all logs.

Audit logging is typically sensitive and important but monitored separate from error logs which is why these two new log levels were introduced.

Log levels

Each log level corresponds to a valid configuration value.

$ log.trace(message[, attachment]);
> [TRACE] ...

$ log.debug(message[, attachment]);
> [DEBUG] ... 

$ log.info(message[, attachment]);
> [INFO] ...

$ log.warn(message[, attachment]);
$ log.warning(message[, attachment]);
> [WARNING] ...

$ log.error(message[, attachment]);
> [ERROR] ...

$ log.critical(message[, attachment]);
> [CRITICAL] ...

$ log.audit(message[, attachment]);
> [AUDIT] ...

$ log.auditAlert(message[, attachment]);
> [AUDIT_ALERT] ...

Shorthand functions

Note: The shorthand names are not valid configuration values.

$ log.warn(message[, attachment]); // Shorthand for warning

$ log.err(message[, attachment]); // Shorthand for error

$ log.crit(message[, attachment]); // Shorthand for critical

Current Tags

  • 2.2.2                                ...           latest (10 months ago)

9 Versions

  • 2.2.2                                ...           10 months ago
  • 2.2.1                                ...           a year ago
  • 2.2.0                                ...           a year ago
  • 2.1.0                                ...           a year ago
  • 2.0.1                                ...           a year ago
  • 2.0.0                                ...           a year ago
  • 1.0.2                                ...           2 years ago
  • 1.0.1                                ...           2 years ago
  • 1.0.0                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 2
Last Day 0
Last Week 0
Last Month 11
Dependencies (0)
None
Dev Dependencies (11)

Copyright 2014 - 2017 © taobao.org |