3.0.0 • Published 6 years ago

em-logger v3.0.0

Weekly downloads
-
License
GPL-3.0
Repository
-
Last release
6 years ago

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:

{
    date: Date, //when it was logged
    message : string,
    level: "INFO"|"WARN"|"EXCEPT"|"ERR",
    source: string //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.