Files
undead-logging/test.ts
zombieb 44784130f9 README fixes, new RoundedLocal time format, more local source options
* i wanted to make sure `undefined` was handled properly. seems like it is.
* tested with Bun, works. Deno runs faster though, by about 1.8µs/message construction!
* Removed skeletons from closet (bug fixes)
* Sources can now optionally specify their own time format and/or log timing
* Requests and Responses now can be converted and displayed (no bodies)
2025-07-19 05:00:07 -04:00

63 lines
2.2 KiB
TypeScript

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'));