Add Log-Level to timers

This commit is contained in:
Fabian Stamm
2025-10-29 00:40:30 +01:00
parent 3526766e68
commit c4d2f32701
3 changed files with 8 additions and 8 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "@hibas123/logging", "name": "@hibas123/logging",
"version": "4.0.2", "version": "4.0.4",
"description": "", "description": "",
"type": "module", "type": "module",
"main": "esm/index.js", "main": "esm/index.js",

View File

@ -139,17 +139,17 @@ export abstract class LoggingInterface implements ILoggingInterface {
mark: (label: string) => { mark: (label: string) => {
timer.marks.push({ time: LoggingBase.nativeFunctions.startTimer(), name: label }); timer.marks.push({ time: LoggingBase.nativeFunctions.startTimer(), name: label });
}, },
end: () => this.timeEnd(id), end: (level?: LoggingTypes) => this.timeEnd(id, level),
}; };
} }
timeEnd(id: string) { timeEnd(id: string, level: LoggingTypes = LoggingTypes.Debug): number {
let timer = this.#timerMap.get(id); let timer = this.#timerMap.get(id);
if (timer) { if (timer) {
let end_time = LoggingBase.nativeFunctions.startTimer(); let end_time = LoggingBase.nativeFunctions.startTimer();
let diff = LoggingBase.nativeFunctions.diffTime(timer.start, end_time); let diff = LoggingBase.nativeFunctions.diffTime(timer.start, end_time);
this.message(LoggingTypes.Debug, this.#names, [ this.message(level, this.#names, [
Format.green(`[${timer.name}]`), Format.green(`[${timer.name}]`),
`->`, `->`,
Format.blue(diff.toFixed(4)), Format.blue(diff.toFixed(4)),
@ -160,7 +160,7 @@ export abstract class LoggingInterface implements ILoggingInterface {
let last_mark = timer.start; let last_mark = timer.start;
for (let mark of timer.marks) { for (let mark of timer.marks) {
let diff = LoggingBase.nativeFunctions.diffTime(last_mark, mark.time); let diff = LoggingBase.nativeFunctions.diffTime(last_mark, mark.time);
this.message(LoggingTypes.Debug, [...this.#names, timer.name], [ this.message(level, [...this.#names, timer.name], [
Format.green(`[${mark.name}]`), Format.green(`[${mark.name}]`),
`->`, `->`,
Format.blue(diff.toFixed(4)), Format.blue(diff.toFixed(4)),
@ -169,7 +169,7 @@ export abstract class LoggingInterface implements ILoggingInterface {
last_mark = mark.time; last_mark = mark.time;
} }
let diff = LoggingBase.nativeFunctions.diffTime(last_mark, end_time); let diff = LoggingBase.nativeFunctions.diffTime(last_mark, end_time);
this.message(LoggingTypes.Debug, [...this.#names, timer.name], [ this.message(level, [...this.#names, timer.name], [
Format.green(`[end]`), Format.green(`[end]`),
`->`, `->`,
Format.blue(diff.toFixed(4)), Format.blue(diff.toFixed(4)),

View File

@ -241,7 +241,7 @@ export interface Adapter {
export interface ILoggingTimer { export interface ILoggingTimer {
mark: (label: string) => void; mark: (label: string) => void;
end: () => number; end: (level?: LoggingTypes) => number;
} }
export interface ILoggingInterface { export interface ILoggingInterface {
@ -251,7 +251,7 @@ export interface ILoggingInterface {
error(...message: any[]): void; error(...message: any[]): void;
time(name?: string): ILoggingTimer; time(name?: string): ILoggingTimer;
timeEnd(id: string): number; timeEnd(id: string, level?: LoggingTypes): number;
getChild(name: string): ILoggingInterface; getChild(name: string): ILoggingInterface;
} }