Added global time format and log timing controls using LoggingConfiguration
* Bench doc fixes * README fixes * Added test scripts in `tests/`
This commit is contained in:
43
README.md
43
README.md
@@ -1,6 +1,11 @@
|
||||
# Undead Logging
|
||||
Logging for stupid idiots like me
|
||||
|
||||
* Pluggable event listeners
|
||||
* Per-source hushing, global log type hushing
|
||||
* Log timing control
|
||||
* Time display modes
|
||||
|
||||
```ts
|
||||
import Logging from "@proxnet/undead-logging"
|
||||
|
||||
@@ -107,6 +112,44 @@ LoggingConfiguration.logTiming = LogTiming.Sync;
|
||||
LoggingConfiguration.logTiming = LogTiming.Deferred;
|
||||
```
|
||||
|
||||
You might prefer to defer logs in asynchronous situations where order does not matter and<br>
|
||||
you'd like to prevent slowing down I/O.<br>
|
||||
You might also prefer to reset all sources to synchronous logging during app shutdown.<br>
|
||||
This can help debug issues with how your app closes. (see example below)
|
||||
|
||||
## Global resets
|
||||
Every source is tracked by this module in a `Set`.
|
||||
|
||||
You can reset every source's log timing or time format with `LoggingConfiguration.reset(something)`.<br>
|
||||
The corresponding property will be updated on `LoggingConfiguration`:
|
||||
|
||||
```ts
|
||||
import Logging, { LoggingConfiguration, LogTiming } from "@proxnet/undead-logging";
|
||||
|
||||
const log = new Logging("Logger");
|
||||
|
||||
log.logTiming = LogTiming.Sync; // the default
|
||||
LoggingConfiguration.resetLogTiming = LogTiming.Deferred;
|
||||
|
||||
// both are LogTiming.Deferred
|
||||
log.d(`My log timing: LogTiming.${LogTiming[log.logTiming]}`);
|
||||
log.d(`Global: LogTiming.${LogTiming[LoggingConfiguration.logTiming]}`);
|
||||
```
|
||||
|
||||
This is useful when you want to use synchronous logging during a shutdown:
|
||||
```ts
|
||||
// something is keeping the event loop alive (HTTP server, a database, some I/O?)
|
||||
|
||||
LoggingConfiguration.logTiming = LogTiming.Deferred;
|
||||
const log = new Logging("Main");
|
||||
|
||||
Deno.addSignalListener('SIGINT', () => {
|
||||
LoggingConfiguration.resetLogTiming = LogTiming.Sync;
|
||||
});
|
||||
```
|
||||
|
||||
See [`tests/shutdown.ts`.](./tests/shutdown.ts)
|
||||
|
||||
## [Benchmarks](./BENCH.md)
|
||||
|
||||
## Contributing
|
||||
|
||||
Reference in New Issue
Block a user