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

deprecate(log): deprecate internal utility methods #4436

Merged
merged 4 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
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
8 changes: 7 additions & 1 deletion log/base_handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,20 @@ export class BaseHandler {
if (this.level > logRecord.level) return;

const msg = this.format(logRecord);
this.log(msg);
this.#log(msg);
}

format(logRecord: LogRecord): string {
return this.formatter(logRecord);
}

/**
* @deprecated (will be removed in 0.220.0)
*/
log(_msg: string) {}
#log(msg: string) {
this.log(msg);
}
setup() {}
destroy() {}

Expand Down
11 changes: 8 additions & 3 deletions log/console_handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,17 @@
let msg = super.format(logRecord);

if (this.#useColors) {
msg = this.applyColors(msg, logRecord.level);
msg = this.#applyColors(msg, logRecord.level);
}

return msg;
}

#applyColors(msg: string, level: number): string {
return this.applyColors(msg, level);
}
/**
* @deprecated (will be removed in 0.220.0)
*/
applyColors(msg: string, level: number): string {
switch (level) {
case LogLevels.INFO:
Expand All @@ -51,7 +56,7 @@
return msg;
}

override log(msg: string) {
override #log(msg: string) {

Check warning on line 59 in log/console_handler.ts

View check run for this annotation

Codecov / codecov/patch

log/console_handler.ts#L59

Added line #L59 was not covered by tests
console.log(msg);
}
}
7 changes: 7 additions & 0 deletions log/file_handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@
}
}

#flush() {
this.#flush();
}

Check warning on line 90 in log/file_handler.ts

View check run for this annotation

Codecov / codecov/patch

log/file_handler.ts#L88-L90

Added lines #L88 - L90 were not covered by tests

/**
* @deprecated (will be removed in 0.220.0)
*/
flush() {
if (this._pointer > 0 && this._file) {
let written = 0;
Expand Down
12 changes: 9 additions & 3 deletions log/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ export class Logger {
let logMessage: string;
if (msg instanceof Function) {
fnResult = msg();
logMessage = this.asString(fnResult);
logMessage = this.#asString(fnResult);
} else {
logMessage = this.asString(msg);
logMessage = this.#asString(msg);
}
const record: LogRecord = new LogRecord({
msg: logMessage,
Expand All @@ -138,6 +138,12 @@ export class Logger {
return msg instanceof Function ? fnResult : msg;
}

#asString(data: unknown, isProperty = false): string {
return this.asString(data, isProperty);
}
/**
* @deprecated (will be removed in 0.220.0)
*/
asString(data: unknown, isProperty = false): string {
if (typeof data === "string") {
if (isProperty) return `"${data}"`;
Expand All @@ -156,7 +162,7 @@ export class Logger {
} else if (typeof data === "object") {
return `{${
Object.entries(data)
.map(([k, v]) => `"${k}":${this.asString(v, true)}`)
.map(([k, v]) => `"${k}":${this.#asString(v, true)}`)
.join(",")
}}`;
}
Expand Down
9 changes: 7 additions & 2 deletions log/rotating_file_handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,20 @@ export class RotatingFileHandler extends FileHandler {
const msgByteLength = this._encoder.encode(msg).byteLength + 1;

if (this.#currentFileSize + msgByteLength > this.#maxBytes) {
this.rotateLogFiles();
this.#rotateLogFiles();
this.#currentFileSize = 0;
}

super.log(msg);

this.#currentFileSize += msgByteLength;
}

#rotateLogFiles() {
this.rotateLogFiles();
}
/**
* @deprecated (will be removed in 0.220.0)
*/
rotateLogFiles() {
this.flush();
this._file!.close();
Expand Down