JSW-Logger
Javascript logging module which writes in the console all warnings and erros
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
;
Node JS
var JSWLogger = JSWLogger;
Browser
<!-- This exposes a global "JSWLogger" variable -->
Instantiating
We can instanciate the logger passing a bunch of options:
var Logger = JSWLogger;
Or we can retrieve the instance with the options by default:
var Logger = JSWLoggerinstance;
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:
Name | Level | Method | Uses |
---|---|---|---|
Silly | 6 | Logger.silly | Some dummy logs, less relevants than a debug |
Debug | 5 | Logger.debug | For debugging purposes |
Verbose | 4 | Logger.verbose | For extended log messages |
Log | 3 | Logger.log | The standar logging |
Info | 2 | Logger.info | To show relevant information messages |
Logger.inform | Works as an alias for "info" | ||
Logger.information | Worksas an alias for "info" | ||
Warn | 1 | Logger.warn | To show application warnings |
Logger.warning | Works as an alias for "warn" | ||
Error | 0 | Logger.error | To output error generated by the application |
Logger.throw | Same 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; // -> outputs nothing, as the default is log (2)Logger; // -> INFO: Some informative message// Can use interpolationLogger; // -> WARN: Be careful Ryan!Logger; // -> ERROR: Line 562 doesn't compile
License
MIT