import Logging, { LoggingListeners, LoggingConfiguration, MessageType, MessageTypeVisibility, TimeFormat, LogTiming } from "./mod.ts"; import { setImmediate } from "node:timers/promises"; 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()}`); }); } LoggingConfiguration.timeFormat = TimeFormat.Utc; const log = new Logging("Test1"); log.i("Hello World!"); log.visible = false; log.e('I should not be visible.'); log.visible = true; log.e('Now I should be visible! (above is all UTC time format)'); const logg = new Logging("Test2"); logg.w(`Uh oh..`); logg.d(`Here's some info that tells you about that warning:`, new Error('Uh oh..')); if (changeTimeFormat) logg.timeFormat = TimeFormat.Unix; logg.i(`Unix time!`); if (changeTimeFormat) logg.timeFormat = TimeFormat.Local; logg.i(`Process time!`); if (changeTimeFormat) logg.timeFormat = TimeFormat.Utc; logg.logTiming = LogTiming.Deferred; logg.log(MessageType.Network, "Deferred mode and RoundedLocal time! (shouldn't be UTC)"); if (changeTimeFormat) logg.timeFormat = TimeFormat.RoundedLocal; setImmediate(() => { // all should NOT be local mode MessageTypeVisibility.Error = false; logg.error("I can't be seen!"); log.error('Same!'); log.n("I *can* be seen!"); }); // the big red error const world = null; if (changeTimeFormat) log.timeFormat = TimeFormat.Utc; log.log(MessageType.Error, Object, "<-- nasty", 0, undefined, null, JSON.stringify({"hello": world})); LoggingConfiguration.logTiming = LogTiming.Sync; LoggingConfiguration.timeFormat = TimeFormat.Unix; 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'));