em-logger
TypeScript icon, indicating that this package has built-in type declarations

3.0.0 • Public • Published

Logger

Log event dispatcher

has 4 levels : INFO, WARN, EXCEPT, ERR

can be subscribed to, and unsubscribed from

uses a static context. this means that this is a system or sandbox wide logging system.

Logging an event

1. build a logger object

let log = new Logger("CurrentPackage");

the "CurrentPackage" exists to reference the origin of the log event

2. throw an event

log.except("some exception has been thrown")

Available methods:

  1. log.info,
  2. log.warn,
  3. log.except,
  4. log.err

events bubble up: errors will be shown to except, warn and info subscribers as well, while except subscribers will only see except and err events.

Subscribing to a log

to read the log, you need to subscribe to a log level by calling a static class

Logger.subscribe.to.WARN((event : Event)=>{...});

this lambda will be called every time a WARN, EXCEPT or ERR event is thrown.

Event object:

{
    dateDate, //when it was logged
    message : string,
    level"INFO"|"WARN"|"EXCEPT"|"ERR",
    sourcestring //where the message came from (defined in constructor)
}

Unsubscribing from the log

a subscription returns a token that can be used to unsubscribe.

let token = Logger.subscribe.to.WARN((event : Event)=>{...});
Logger.unsubscribe(token);

now that specific subscription is canceled.

Package Sidebar

Install

npm i em-logger

Weekly Downloads

0

Version

3.0.0

License

GPL-3.0

Unpacked Size

23.5 kB

Total Files

11

Last publish

Collaborators

  • emdiet