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)
This commit is contained in:
43
test.ts
43
test.ts
@@ -1,44 +1,63 @@
|
||||
import Logging, { LoggingListeners, LoggingConfiguration, MessageType, MessageTypeVisibility, TimeFormat, LogTiming } from "@proxnet/undead-logging";
|
||||
import Logging, { LoggingListeners, LoggingConfiguration, MessageType, MessageTypeVisibility, TimeFormat, LogTiming } from "./mod.ts";
|
||||
import { setImmediate } from "node:timers/promises";
|
||||
import process from "node:process";
|
||||
|
||||
const debug = Deno.args[0] == 'true';
|
||||
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(`[d] ${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!');
|
||||
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..'));
|
||||
|
||||
LoggingConfiguration.timeFormat = TimeFormat.Unix;
|
||||
if (changeTimeFormat) logg.timeFormat = TimeFormat.Unix;
|
||||
logg.i(`Unix time!`);
|
||||
|
||||
LoggingConfiguration.timeFormat = TimeFormat.Local;
|
||||
if (changeTimeFormat) logg.timeFormat = TimeFormat.Local;
|
||||
logg.i(`Process time!`);
|
||||
|
||||
LoggingConfiguration.timeFormat = TimeFormat.Utc;
|
||||
LoggingConfiguration.logTiming = LogTiming.Deferred;
|
||||
logg.log(MessageType.Network, "Deferred mode!");
|
||||
if (changeTimeFormat) logg.timeFormat = TimeFormat.Utc;
|
||||
logg.logTiming = LogTiming.Deferred;
|
||||
logg.log(MessageType.Network, "Deferred mode and RoundedLocal time! (shouldn't be UTC)");
|
||||
|
||||
LoggingConfiguration.timeFormat = TimeFormat.Local;
|
||||
if (changeTimeFormat) logg.timeFormat = TimeFormat.RoundedLocal;
|
||||
setImmediate(() => {
|
||||
// all should be local mode
|
||||
// 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'));
|
||||
Reference in New Issue
Block a user