40 lines
1.1 KiB
TypeScript
40 lines
1.1 KiB
TypeScript
import Logging, { LoggingConfiguration, LoggingListeners } from "../src/mod.ts";
|
|
|
|
const debug = Deno.args[Deno.args.length - 1] === 'true';
|
|
console.debug(`Debug mode: ${debug}`);
|
|
|
|
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()}${Logging.getNewline()}`);
|
|
});
|
|
}
|
|
|
|
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'));
|
|
|
|
class CustomClass {
|
|
|
|
foo: string;
|
|
bar: number;
|
|
|
|
constructor(foo: string, bar: number) {
|
|
this.foo = foo;
|
|
this.bar = bar;
|
|
}
|
|
|
|
}
|
|
|
|
LoggingConfiguration.addConversion<CustomClass>({
|
|
condition: arg => arg instanceof CustomClass,
|
|
converter: arg => `CustomClass; foo:${arg.foo}; bar:${arg.bar};`
|
|
});
|
|
|
|
const log = new Logging("ConvertTest");
|
|
|
|
log.d(new CustomClass("baz", 39)); |