Socket
Socket
Sign inDemoInstall

jsw-logger

Package Overview
Dependencies
10
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    jsw-logger

Javascript logging module that inherits Winston Logger (https://github.com/winstonjs/winston) module.


Version published
Weekly downloads
1
decreased by-80%
Maintainers
1
Install size
5.69 MB
Created
Weekly downloads
 

Changelog

Source

1.2.6 (2018-08-11)

Bug Fixes

  • Remove the log when not in a browser #7 (950893e)

<a name="1.2.5"></a>

Readme

Source

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

Keywords

FAQs

Last updated on 11 Aug 2018

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc