Skip to content

Commit

Permalink
deprecate(log): deprecate internal utility methods (denoland#4436)
Browse files Browse the repository at this point in the history
initial commit
  • Loading branch information
timreichen authored Apr 10, 2024
1 parent 31c7786 commit 42df58a
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 9 deletions.
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 @@ export class ConsoleHandler extends BaseHandler {
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 @@ export class ConsoleHandler extends BaseHandler {
return msg;
}

override log(msg: string) {
override #log(msg: string) {
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 @@ export class FileHandler extends BaseHandler {
}
}

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

/**
* @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

0 comments on commit 42df58a

Please sign in to comment.