1.2.6 • Published 6 years ago

jsw-logger v1.2.6

Weekly downloads
6
License
MIT
Repository
github
Last release
6 years ago

JSW-Logger

Javascript logging module which writes in the console all warnings and erros

Package Version NodeJS Version

Linux Build Windows Build Test Coverage Downloads Documentation Status

CodeClimate GPA CodeClimate Issues CodeClimate Coverage

Codacy

Installation

npm install --save jsw-logger

Usage

Currently, JSW-Logger can be used within a TypeScript based project, as a node dependency or directly in the browser.

Declaration:

First we need to import the dependency:

Typescript

import { JSWLogger } from "jsw-logger";

Node JS

var JSWLogger = require("jsw-logger").JSWLogger;

Browser

<script src="path/to/deps/dist/jsw-logger.min.js"></script>
<!-- This exposes a global "JSWLogger" variable -->

Instantiating

We can instanciate the logger passing a bunch of options:

var Logger = JSWLogger.getInstance({
    level: 2,   // logs "info", "warn" and "error" by default
    hideAllLogs: false, // hides messsages from being logged
    hideLevelLog: false,    // hides the "LOG: " from the begining of the message
    throwError: true   // throw an error when "Logger.throw"
});

Or we can retrieve the instance with the options by default:

var Logger = JSWLogger.instance;

Also, the options can only by setted when instantiating with the first way. To change them, we should access the options object: Logger.options.throwError = false Or we can drop the instance so we can regenerate it: JSWLogger.__dropInstance()

Note that as this is a singleton (can only be instantiated once), so if you drop the instance, it will be dropped for all

Logging

The level logging hierarchy is as follows:

NameLevelMethodUses
Silly6Logger.sillySome dummy logs, less relevants than a debug
Debug5Logger.debugFor debugging purposes
Verbose4Logger.verboseFor extended log messages
Log3Logger.logThe standar logging
Info2Logger.infoTo show relevant information messages
Logger.informWorks as an alias for "info"
Logger.informationWorksas an alias for "info"
Warn1Logger.warnTo show application warnings
Logger.warningWorks as an alias for "warn"
Error0Logger.errorTo output error generated by the application
Logger.throwSame as "error", but throws an Exception is configured to

The lower we set the level whe instanciating, the less methods will output something. Eg.:

Logger.debug("Not shown"); // -> outputs nothing, as the default is log (2)
Logger.info("Some informative message"); // -> INFO: Some informative message
// Can use interpolation
Logger.warn("Be careful %s!", "Ryan"); // -> WARN: Be careful Ryan!
Logger.error("Line %d doesn't compile", 562); // -> ERROR: Line 562 doesn't compile

License

MIT

1.2.6

6 years ago

1.2.5

6 years ago

1.2.4

7 years ago

1.2.3

7 years ago

1.2.2

7 years ago

1.2.0

7 years ago

1.0.5

8 years ago

1.0.4

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago

1.0.0-0

8 years ago