Compare commits

..

No commits in common. "6daf815ea8b3eed4579b2b248ffba7c01eec6bc7" and "96d7808f353a7f00c2676f6d05eab51f54e3a647" have entirely different histories.

6 changed files with 3864 additions and 20 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "logging", "name": "logging",
"version": "3.0.3", "version": "3.0.0",
"description": "", "description": "",
"author": "Fabian Stamm <dev@fabianstamm.de>", "author": "Fabian Stamm <dev@fabianstamm.de>",
"contributors": [], "contributors": [],

3844
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{ {
"name": "@hibas123/logging", "name": "@hibas123/logging",
"version": "3.0.3", "version": "3.0.0",
"description": "", "description": "",
"main": "out/index.js", "main": "out/index.js",
"types": "out/index.d.ts", "types": "out/index.d.ts",

View File

@ -134,7 +134,7 @@ export abstract class LoggingInterface implements ILoggingInterface {
this.#timerMap.set(id, { this.#timerMap.set(id, {
name: id, name: id,
start: LoggingBase.nativeFunctions.startTimer(), start: Logging.nativeFunctions.startTimer(),
}); });
return { return {
@ -146,7 +146,7 @@ export abstract class LoggingInterface implements ILoggingInterface {
timeEnd(id: string) { timeEnd(id: string) {
let timer = this.#timerMap.get(id); let timer = this.#timerMap.get(id);
if (timer) { if (timer) {
let diff = LoggingBase.nativeFunctions.endTimer(timer.start); let diff = Logging.nativeFunctions.endTimer(timer.start);
this.message(LoggingTypes.Debug, this.#names, [ this.message(LoggingTypes.Debug, this.#names, [
Format.green(`[${timer.name}]`), Format.green(`[${timer.name}]`),
@ -163,13 +163,13 @@ export abstract class LoggingInterface implements ILoggingInterface {
abstract getChild(name: string): ILoggingInterface; abstract getChild(name: string): ILoggingInterface;
} }
export class LoggingBase extends LoggingInterface { export class Logging extends LoggingInterface {
private static [InitialisedAdapters] = new Map<Adapter, number>(); private static [InitialisedAdapters] = new Map<Adapter, number>();
public static nativeFunctions: INativeFunctions = DefaultNativeFunctions; public static nativeFunctions: INativeFunctions = DefaultNativeFunctions;
static DecoupledLogging = class extends LoggingInterface { static DecoupledLogging = class extends LoggingInterface {
#lg: LoggingBase; #lg: Logging;
constructor(names: string[], lg: LoggingBase) { constructor(names: string[], lg: Logging) {
super(names); super(names);
this.#lg = lg; this.#lg = lg;
} }
@ -179,7 +179,7 @@ export class LoggingBase extends LoggingInterface {
} }
getChild(name: string) { getChild(name: string) {
return new LoggingBase.DecoupledLogging([this.names, name], this.#lg); return new Logging.DecoupledLogging([this.names, name], this.#lg);
} }
}; };
@ -221,13 +221,13 @@ export class LoggingBase extends LoggingInterface {
const add = () => { const add = () => {
this.#adapters.add(adapter); this.#adapters.add(adapter);
if (LoggingBase[InitialisedAdapters].has(adapter)) { if (Logging[InitialisedAdapters].has(adapter)) {
LoggingBase[InitialisedAdapters].set( Logging[InitialisedAdapters].set(
adapter, adapter,
LoggingBase[InitialisedAdapters].get(adapter) + 1 Logging[InitialisedAdapters].get(adapter) + 1
); );
} else { } else {
LoggingBase[InitialisedAdapters].set(adapter, 1); Logging[InitialisedAdapters].set(adapter, 1);
} }
}; };
@ -239,7 +239,7 @@ export class LoggingBase extends LoggingInterface {
} }
getChild(name: string): ILoggingInterface { getChild(name: string): ILoggingInterface {
return new LoggingBase.DecoupledLogging([...this.names, name], this); return new Logging.DecoupledLogging([...this.names, name], this);
} }
protected message( protected message(
@ -389,15 +389,15 @@ export class LoggingBase extends LoggingInterface {
this.#closed = true; this.#closed = true;
this.#adapters.forEach((adapter) => { this.#adapters.forEach((adapter) => {
const cnt = LoggingBase[InitialisedAdapters].get(adapter); const cnt = Logging[InitialisedAdapters].get(adapter);
if (!cnt) { if (!cnt) {
//TODO: should not happen! //TODO: should not happen!
} else { } else {
if (cnt <= 1) { if (cnt <= 1) {
adapter.close(); adapter.close();
LoggingBase[InitialisedAdapters].delete(adapter); Logging[InitialisedAdapters].delete(adapter);
} else { } else {
LoggingBase[InitialisedAdapters].set(adapter, cnt - 1); Logging[InitialisedAdapters].set(adapter, cnt - 1);
} }
} }
}); });

View File

@ -1,5 +1,5 @@
import { LoggingBase } from "./base.js"; import { Logging as LoggingClass } from "./base.js";
export { LoggingBase } from "./base.js"; export { Logging } from "./base.js";
export { ConsoleAdapter } from "./consolewriter.js"; export { ConsoleAdapter } from "./consolewriter.js";
export { ILoggingOptions, INativeFunctions } from "./base.js"; export { ILoggingOptions, INativeFunctions } from "./base.js";
@ -16,6 +16,6 @@ export {
IFormatted, IFormatted,
} from "./types.js"; } from "./types.js";
const Logging = new LoggingBase(); const Logging = new LoggingClass();
export default Logging; export default Logging;

View File

@ -1,6 +1,6 @@
import Logging from "./index.js"; import Logging from "./index.js";
import { LoggingBase, LoggingTypes, Format } from "./index.js"; import { Logging as LoggingBase, LoggingTypes, Format } from "./index.js";
Logging.log("test"); Logging.log("test");
Logging.log("i", "am", { a: "an" }, 1000); Logging.log("i", "am", { a: "an" }, 1000);