breaking change. it works better.
This commit is contained in:
7
tests/bright.ts
Normal file
7
tests/bright.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import Logging from "../src/mod.ts";
|
||||
|
||||
const log = new Logging("NotBright");
|
||||
|
||||
log.bright = false;
|
||||
|
||||
log.i("Not Bright");
|
||||
@@ -1,16 +1,14 @@
|
||||
import Logging, { LoggingListeners } from "../mod.ts";
|
||||
import process from "node:process";
|
||||
import Logging, { LoggingConfiguration, LoggingListeners } from "../src/mod.ts";
|
||||
|
||||
const debug = process.argv[process.argv.length - 1] == 'true';
|
||||
const debug = Deno.args[Deno.args.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}`);
|
||||
console.debug(`[d] ${msg}`);
|
||||
});
|
||||
LoggingListeners.onmsg('type', (msg, type, source, time) => {
|
||||
console.debug(`[D] M:'${msg}' T:${type} S:'${source}' TM:${time.getTime()}`);
|
||||
console.debug(`[D] M:'${msg}' T:${type} S:'${source}' TM:${time.getTime()}${Logging.getNewline()}`);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -18,4 +16,25 @@ 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'));
|
||||
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));
|
||||
@@ -1,4 +1,4 @@
|
||||
import Logging, { LoggingConfiguration, LogTiming } from "@proxnet/undead-logging";
|
||||
import Logging, { LoggingConfiguration, LogTiming } from "./../src/mod.ts";
|
||||
|
||||
const log = new Logging("Logger");
|
||||
|
||||
|
||||
28
tests/priority.ts
Normal file
28
tests/priority.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import Logging, { LoggingConfiguration } from "@proxnet/undead-logging";
|
||||
|
||||
class CustomError extends Error {
|
||||
|
||||
someProperty: string
|
||||
|
||||
constructor(someProp: string) {
|
||||
super("Something went wrong.");
|
||||
this.someProperty = someProp;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
LoggingConfiguration.clearConversions();
|
||||
LoggingConfiguration.addConversion<CustomError>({
|
||||
condition: arg => arg instanceof CustomError,
|
||||
converter: arg => `CustomError: someProperty:${arg.someProperty}; ${arg.stack || arg.message}`,
|
||||
priority: -1
|
||||
});
|
||||
LoggingConfiguration.addConversion<Error>({
|
||||
condition: arg => arg instanceof Error,
|
||||
converter: arg => `Error: ${arg.stack || arg.message}`,
|
||||
priority: 1
|
||||
});
|
||||
|
||||
const log = new Logging("PriorityTest");
|
||||
|
||||
log.i(new CustomError("'Hello World!'"));
|
||||
8
tests/time.ts
Normal file
8
tests/time.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import Logging, { LoggingConfiguration } from "../src/mod.ts";
|
||||
import { TimeFormat } from "../src/types.ts";
|
||||
|
||||
LoggingConfiguration.timeFormat = TimeFormat.None;
|
||||
|
||||
const log = new Logging("NoDate");
|
||||
|
||||
log.i('No Date');
|
||||
@@ -1,7 +1,7 @@
|
||||
import Logging, {
|
||||
LoggingConfiguration,
|
||||
LogTiming,
|
||||
} from "../mod.ts";
|
||||
} from "./../src/mod.ts";
|
||||
|
||||
LoggingConfiguration.logTiming = LogTiming.Microtask;
|
||||
// high-priority logs
|
||||
|
||||
Reference in New Issue
Block a user