Jamsek-m / logger-js

Client logger library for enhanced logging

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

npm

Logger

Client logger library for enhanced logging

Client library for enhancing browser's console. It allows you to define logging level and therefore control what get's logged and what not.

Installation

In terminal run:

npm install --save @mjamsek/logger

Usage

To use logger, all you need to do is to use this call:

Logger.getInstance().log("Hello world!");
// outputs: Hello world!

Log level

By default, log level is set to INFO. You can change the level with call:

Logger.setLogLevel(LogLevel.WARN);

Available log levels:

  • DEBUG
  • FINEST
  • FINE
  • INFO (default)
  • WARN
  • ERROR
  • OFF (disables logging)

Setting log level means all lower levels will not be logging messages anymore.

Logger.setLogLevel(LogLevel.DEBUG);
Logger.getInstance().debug("Hello debug!");
Logger.getInstance().info("Hello info!");
// outputs:
// Hello debug!
// Hello info!

Logger.setLogLevel(LogLevel.INFO);
Logger.getInstance().debug("Hello debug!");
Logger.getInstance().info("Hello info!");
// outputs:
// Hello info!

Prefix

You can also set prefix to separate your logs from other logs that may be used in application.

Logger.setPrefix("MyApp");
Logger.getInstance().info("Hello world!");
// outputs: [MyApp] Hello world!

Changelog

Recent changes can be viewed on Github on the Releases Page

Contribute

See the contributing docs

When submitting an issue, please follow the guidelines.

License

MIT

About

Client logger library for enhanced logging

License:MIT License


Languages

Language:TypeScript 81.1%Language:JavaScript 18.9%