Skip to content

Commit

Permalink
fix(di): clean commented code and use DI fn API to create context cor…
Browse files Browse the repository at this point in the history
…rectly
  • Loading branch information
Romakita committed Nov 8, 2024
1 parent f12f56b commit 6406314
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 15 deletions.
3 changes: 2 additions & 1 deletion packages/di/src/node/domain/ContextLogger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {Hooks} from "@tsed/core";
import {levels, LogLevel} from "@tsed/logger";

import {DILogger} from "../../common/index.js";
import {logger as injectLogger} from "../fn/logger.js";

export interface ContextLoggerOptions extends Record<string, any> {
id: string;
Expand All @@ -28,7 +29,7 @@ export class ContextLogger {
constructor({id, logger, dateStart = new Date(), level = "all", maxStackSize = 30, additionalProps}: ContextLoggerOptions) {
this.dateStart = dateStart;
this.id = id;
this.#logger = logger;
this.#logger = logger || injectLogger();
this.#additionalProps = additionalProps;
this.level = (LEVELS[level.toUpperCase()] || LEVELS.ALL) as LogLevel;
this.maxStackSize = maxStackSize;
Expand Down
15 changes: 1 addition & 14 deletions packages/di/src/node/domain/DIContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,7 @@ export class DIContext {
* Logger attached to the context request.
*/
get logger() {
this.#logger =
this.#logger ||
new ContextLogger({
...this.opts,
logger: logger()
});
this.#logger = this.#logger || new ContextLogger(this.opts);
return this.#logger;
}

Expand Down Expand Up @@ -84,14 +79,6 @@ export class DIContext {
return Promise.all([this.#container?.destroy(), this.#logger?.flush(true)]);
}

// emit(eventName: string, ...args: any[]) {
// return $emit(eventName, ...args);
// }

// runInContext<Result = unknown>(next: (...args: unknown[]) => Result): Promise<Result> {
// return runInContext<Result>(this, next);
// }

cache<Value = any>(key: string, cb: () => Value): Value {
if (!this.has(key)) {
this.set(key, cb());
Expand Down

0 comments on commit 6406314

Please sign in to comment.