This package has been deprecated

Author message:

This package is no longer maintained; there are many more better alternatives out there.

extended-console

2.2.0 • Public • Published

extended-console

Extends default console logging with various utilities.

Features

  • Prepend timestamp to output using Moment.js' format
  • Prepend log level (ie, log, inf, war, err)
  • Attach events to be called when something is logged using any of the 4 log functions

Usage

First install it using npm

npm install extended-console

Then simply require it and log away!

require("extended-console");

console.log("Log away!");

Options

Options are located within the console.extended object.

  • showTimestamp ( boolean ) Whether to prepend a timestamp to output
  • timestampFormat ( string ) Format for timestamp. Uses Moment.js' format
  • showLogLevel ( boolean ) Whether to prepend the log level to output

For example

require("extended-console");

console.extended.timestampFormat = "YYYY-MM-DD HH:mm";
console.log("Custom timestamp format!");

Events

This module extends the console to act as a standard event emitter. You can use standard events.EventEmitter methods such as .on and .addListener on the console.extended object. The event names are as follow: log, inf, war, err. Be careful not to call any of the logging functions inside of an event callback for that logging function itself, for it will result in a stack overflow.

Example

console.extended.on("err", function() {
	process.stdout.write("Error event listener called\n");
});
console.error("Error event listener test");

Changelog

2.2.0

  • Events now called with potential prepended string in arguments
  • No longer prepend empty string (used to produce superfluous space character)

2.1.1

  • Fixed bug that caused events not to be emitted

2.1.0

  • Added event support
  • Changed log level logging to use following short names: log, inf, war, err. This is for consistency with events
  • Changed to using Semantic Versioning. Changed version numbers to reflect what should have been in this README file.

2.0.0

(previously 0.2)

Breaking changes

  • Added option to prepend log level (on by default)
  • Switched to Moment.js for date formatting
  • Surrounding brackets are no longer part of timestamp format. They are always automatically there

1.0.0

(previously 0.1)

  • Initial release

License

MIT (see included LICENSE)

Readme

Keywords

none

Package Sidebar

Install

npm i extended-console

Weekly Downloads

2

Version

2.2.0

License

BSD

Last publish

Collaborators

  • npm