Files
undead-logging/test.ts

44 lines
1.3 KiB
TypeScript

import Logging, { LoggingListeners, LoggingConfiguration, MessageType, MessageTypeVisibility, TimeFormat, LogTiming } from "@proxnet/undead-logging";
import { setImmediate } from "node:timers/promises";
const debug = Deno.args[0] == 'true';
if (debug) {
LoggingListeners.onmsg('basic', msg => {
console.debug(`[d] ${msg}`);
});
LoggingListeners.onmsg('type', (msg, type, source, time) => {
console.debug(`[D] M:'${msg}' T:${type} S:'${source}' TM:${time.getTime()}`);
});
}
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!');
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;
logg.i(`Unix time!`);
LoggingConfiguration.timeFormat = TimeFormat.Local;
logg.i(`Process time!`);
LoggingConfiguration.timeFormat = TimeFormat.Utc;
LoggingConfiguration.logTiming = LogTiming.Deferred;
logg.log(MessageType.Network, "Deferred mode!");
LoggingConfiguration.timeFormat = TimeFormat.Local;
setImmediate(() => {
// all should be local mode
MessageTypeVisibility.Error = false;
logg.error("I can't be seen!");
log.error('Same!');
log.n("I *can* be seen!");
});