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:
21
tests/convert.ts
Normal file
21
tests/convert.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import Logging, { LoggingListeners } from "../mod.ts";
|
||||
import process from "node:process";
|
||||
|
||||
const debug = process.argv[process.argv.length - 1] == 'true';
|
||||
console.debug(`Debug mode: ${debug}`);
|
||||
const changeTimeFormat = process.argv[process.argv.length - 2] == 'true';
|
||||
console.debug(`changeTimeFormat: ${changeTimeFormat}`);
|
||||
if (debug) {
|
||||
LoggingListeners.onmsg('basic', msg => {
|
||||
console.debug(`\r\n[d] ${msg}`);
|
||||
});
|
||||
LoggingListeners.onmsg('type', (msg, type, source, time) => {
|
||||
console.debug(`[D] M:'${msg}' T:${type} S:'${source}' TM:${time.getTime()}`);
|
||||
});
|
||||
}
|
||||
|
||||
const webLog = new Logging("Web");
|
||||
webLog.d(`Following is a Request`);
|
||||
webLog.i(new Request('http://example.com?hello=world', { headers: { 'key1': 'value1', 'key2': 'value2' }}));
|
||||
webLog.d(`Following is a Response`);
|
||||
webLog.i(await fetch('https://example.com'));
|
||||
9
tests/global.ts
Normal file
9
tests/global.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import Logging, { LoggingConfiguration, LogTiming } from "@proxnet/undead-logging";
|
||||
|
||||
const log = new Logging("Logger");
|
||||
|
||||
log.logTiming = LogTiming.Sync;
|
||||
LoggingConfiguration.resetLogTiming = LogTiming.Deferred;
|
||||
|
||||
log.d(`My log timing: LogTiming.${LogTiming[log.logTiming]} (not sync!)`);
|
||||
log.d(`Global: LogTiming.${LogTiming[LoggingConfiguration.logTiming]} (not sync!)`);
|
||||
16
tests/shutdown.ts
Normal file
16
tests/shutdown.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import Logging, { LoggingConfiguration, LogTiming } from "@proxnet/undead-logging";
|
||||
|
||||
//LoggingConfiguration.logTiming = LogTiming.Deferred;
|
||||
|
||||
const log = new Logging("Main");
|
||||
log.i(`Deferred! - LogTiming.${LogTiming[log.logTiming]}`);
|
||||
|
||||
const timeout = setTimeout(() => { log.d(`Interval!`) }, 2000);
|
||||
|
||||
Deno.addSignalListener('SIGINT', () => {
|
||||
clearTimeout(timeout);
|
||||
|
||||
LoggingConfiguration.resetLogTiming = LogTiming.Sync;
|
||||
|
||||
log.i(`Sync! - LogTiming.${LogTiming[LoggingConfiguration.logTiming]}`);
|
||||
});
|
||||
Reference in New Issue
Block a user