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
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>
Instantiating
We can instanciate the logger passing a bunch of options:
var Logger = JSWLogger.getInstance({
level: 2,
hideAllLogs: false,
hideLevelLog: false,
throwError: true
});
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:
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.debug("Not shown");
Logger.info("Some informative message");
Logger.warn("Be careful %s!", "Ryan");
Logger.error("Line %d doesn't compile", 562);
License
MIT