Logger plus

A simple JavaScript library to add optional functionality directly to console.log , avoiding the need to refactor existing code.

Features

Automatic date/time tagging of log messages, with custom date/time format.

Ability to add tags to messages coming from particular functions (including child calls).

Extensible with custom transformations run on messages and objects before they are logged.

Makes changes directly to console.log , so no refactoring required for existing code.

, so no refactoring required for existing code. Supports variations of console.log - namely error and warn for now.

- namely and for now. Works with multiple arguments to the log functions (used in the same way as vanilla console.log - see here)

- see here) Automatically retrieve meta information (such as line-number, calling function, etc.) with micro-templates.

Built for both Node.js and vanilla JavaScript.

Installation

npm install loggerplus --save

Usage

Note: Whilst the features are automatically applied through console.log , you'll still need to use some other functions and variables to activate and configure said features.

Setup

var loggerplus = require("loggerplus");

Vanilla JavaScript

None - Just use window.loggerplus !

Settings

Loggerplus stores its settings in loggerplus.settings .

[Type] (default value) key : Description

[String] ([YYYY-MM-DD, HH:mm:SS.sss]) dateTimeFormat : Sets the format of the date/time output (see date/time tagging).

([YYYY-MM-DD, HH:mm:SS.sss]) : Sets the format of the date/time output (see date/time tagging). [Boolean] (false) useDateTime : Turns on or off date/time tagging.

(false) : Turns on or off date/time tagging. [Boolean] (false) useTags : Turns on or off custom tagging.

(false) : Turns on or off custom tagging. [Boolean] (false) useTextTransformations : Turns on or off custom transformations for text components of the log.

(false) : Turns on or off custom transformations for text components of the log. [Boolean] (false) useObjectTransformations : Turns on or off custom transformations for object components of the log.

(false) : Turns on or off custom transformations for object components of the log. [Boolean] (true) transformTags : Apply text transformations to tags as well as logged text.

(true) : Apply text transformations to tags as well as logged text. [Boolean] (false) disableLogging : Disables console logging (for production code).

(false) : Disables console logging (for production code). [Boolean] (false) useMicroTemplates : Use tinytim and stacktrace-js to provide dynamic logging content.

Logging messages

console.log("Hello World!");

That's it! One of the awesome things about loggerplus is that you can add it to existing code and simply configure it; no refactoring required.

What if I want to use the native console.log somewhere in my code?

Easy! Simply use console.native_log(message);

Note: Loggerplus also works with the following console.log variants (as well as defining their console.native_ equivalents)

console.warn

console.error

Configuring features

Simply use the loggerplus.settings object to turn features on and off.

Features are off by default.

Feature types

Global - Appears in every logged message.

Local - Appears only in logs within the scope of the function to which it is applied.

Persistent - Appears in logs within the scope of the function to which it is applied, as well as any any child (and child-child, child-child-child, etc.) function calls contained within it.

Automatic date/time tagging

Must be activated with useDateTime

Set date/time format

loggerplus.settings.dateTimeFormat = "[YYYY-MM-DD, HH:mm:SS.sss]"; //The default date/time format

Date/time format legend

Y - Year

- Year M - Month

- Month D - Day

- Day H - Hour

- Hour m - Minute

- Minute S - Second

- Second s - Millisecond

The number fills from right to left, padding with 0's if necessary. E.g. (in the year 2016)

YY = 16

=