Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(log): sync level and levelName in BaseHandler #4393

Merged
merged 5 commits into from
Feb 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 26 additions & 7 deletions log/base_handler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { getLevelByName, LevelName } from "./levels.ts";
import { getLevelByName, getLevelName, LevelName, LogLevel } from "./levels.ts";
import type { LogRecord } from "./logger.ts";

export type FormatterFunction = (logRecord: LogRecord) => string;
Expand All @@ -11,14 +11,33 @@
}

export class BaseHandler {
level: number;
levelName: LevelName;
#levelName: LevelName;
#level: LogLevel;
formatter: FormatterFunction;

constructor(levelName: LevelName, options: BaseHandlerOptions = {}) {
this.level = getLevelByName(levelName);
this.levelName = levelName;
this.formatter = options.formatter || DEFAULT_FORMATTER;
constructor(
levelName: LevelName,
{ formatter = DEFAULT_FORMATTER }: BaseHandlerOptions = {},
) {
this.#levelName = levelName;
this.#level = getLevelByName(levelName);
this.formatter = formatter;
}

get level() {
return this.#level;
}
set level(level: LogLevel) {
this.#level = level;
this.#levelName = getLevelName(level);
}

Check warning on line 33 in log/base_handler.ts

View check run for this annotation

Codecov / codecov/patch

log/base_handler.ts#L30-L33

Added lines #L30 - L33 were not covered by tests

get levelName() {
return this.#levelName;
}
set levelName(levelName: LevelName) {
this.#levelName = levelName;
this.#level = getLevelByName(levelName);

Check warning on line 40 in log/base_handler.ts

View check run for this annotation

Codecov / codecov/patch

log/base_handler.ts#L38-L40

Added lines #L38 - L40 were not covered by tests
}

handle(logRecord: LogRecord) {
Expand Down
Loading