From adeec53d5d209ee1c558f2454fddf6f3ccbe7360 Mon Sep 17 00:00:00 2001 From: Asher Gomez Date: Thu, 1 Feb 2024 17:01:37 +1100 Subject: [PATCH 1/2] BREAKING(log): remove deprecated APIs --- log/base_handler_test.ts | 8 ++++---- log/console_handler.ts | 2 +- log/file_handler_test.ts | 16 ++++++++-------- log/levels.ts | 5 ++--- log/logger.ts | 13 +------------ log/logger_test.ts | 16 ++++++++-------- log/mod.ts | 32 +++---------------------------- log/mod_test.ts | 6 +++--- log/rotating_file_handler_test.ts | 16 ++++++++-------- log/test.ts | 2 +- 10 files changed, 39 insertions(+), 77 deletions(-) diff --git a/log/base_handler_test.ts b/log/base_handler_test.ts index 6b633c921557..e6758f9e5017 100644 --- a/log/base_handler_test.ts +++ b/log/base_handler_test.ts @@ -25,7 +25,7 @@ Deno.test("simpleHandler", function () { [ "DEBUG debug-test", "INFO info-test", - "WARNING warning-test", + "WARN warn-test", "ERROR error-test", "CRITICAL critical-test", ], @@ -34,14 +34,14 @@ Deno.test("simpleHandler", function () { LogLevels.INFO, [ "INFO info-test", - "WARNING warning-test", + "WARN warn-test", "ERROR error-test", "CRITICAL critical-test", ], ], [ - LogLevels.WARNING, - ["WARNING warning-test", "ERROR error-test", "CRITICAL critical-test"], + LogLevels.WARN, + ["WARN warn-test", "ERROR error-test", "CRITICAL critical-test"], ], [LogLevels.ERROR, ["ERROR error-test", "CRITICAL critical-test"]], [LogLevels.CRITICAL, ["CRITICAL critical-test"]], diff --git a/log/console_handler.ts b/log/console_handler.ts index 0e4435a32728..e20ff275dba2 100644 --- a/log/console_handler.ts +++ b/log/console_handler.ts @@ -35,7 +35,7 @@ export class ConsoleHandler extends BaseHandler { case LogLevels.INFO: msg = blue(msg); break; - case LogLevels.WARNING: + case LogLevels.WARN: msg = yellow(msg); break; case LogLevels.ERROR: diff --git a/log/file_handler_test.ts b/log/file_handler_test.ts index e3707cc52796..16d0cd39e49f 100644 --- a/log/file_handler_test.ts +++ b/log/file_handler_test.ts @@ -24,7 +24,7 @@ Deno.test({ } } - using testFileHandler = new TestFileHandler("WARNING", { + using testFileHandler = new TestFileHandler("WARN", { filename: LOG_FILE, mode: "w", }); @@ -35,7 +35,7 @@ Deno.test({ new LogRecord({ msg: "The starry heavens above me and the moral law within me.", args: [], - level: LogLevels.WARNING, + level: LogLevels.WARN, loggerName: "default", }), ); @@ -46,7 +46,7 @@ Deno.test({ Deno.test({ name: "FileHandler with mode 'w' will wipe clean existing log file", async fn() { - const fileHandler = new FileHandler("WARNING", { + const fileHandler = new FileHandler("WARN", { filename: LOG_FILE, mode: "w", }); @@ -56,7 +56,7 @@ Deno.test({ new LogRecord({ msg: "Hello World", args: [], - level: LogLevels.WARNING, + level: LogLevels.WARN, loggerName: "default", }), ); @@ -68,7 +68,7 @@ Deno.test({ new LogRecord({ msg: "Hello World", args: [], - level: LogLevels.WARNING, + level: LogLevels.WARN, loggerName: "default", }), ); @@ -83,7 +83,7 @@ Deno.test({ Deno.test({ name: "FileHandler with mode 'x' will throw if log file already exists", fn() { - using fileHandler = new FileHandler("WARNING", { + using fileHandler = new FileHandler("WARN", { filename: LOG_FILE, mode: "x", }); @@ -100,7 +100,7 @@ Deno.test({ Deno.test({ name: "Window unload flushes buffer", async fn() { - const fileHandler = new FileHandler("WARNING", { + const fileHandler = new FileHandler("WARN", { filename: LOG_FILE, mode: "w", }); @@ -126,7 +126,7 @@ Deno.test({ Deno.test({ name: "FileHandler: Critical logs trigger immediate flush", async fn() { - using fileHandler = new FileHandler("WARNING", { + using fileHandler = new FileHandler("WARN", { filename: LOG_FILE, mode: "w", }); diff --git a/log/levels.ts b/log/levels.ts index c42829a2da73..cfeed4674189 100644 --- a/log/levels.ts +++ b/log/levels.ts @@ -9,8 +9,7 @@ export const LogLevels = { NOTSET: 0, DEBUG: 10, INFO: 20, - /** @deprecated (will be removed after 0.214.0) Will be changed to {@linkcode WARN}. */ - WARNING: 30, + WARN: 30, ERROR: 40, CRITICAL: 50, } as const; @@ -30,7 +29,7 @@ const byLevel: Record = { [LogLevels.NOTSET]: "NOTSET", [LogLevels.DEBUG]: "DEBUG", [LogLevels.INFO]: "INFO", - [LogLevels.WARNING]: "WARNING", + [LogLevels.WARN]: "WARN", [LogLevels.ERROR]: "ERROR", [LogLevels.CRITICAL]: "CRITICAL", }; diff --git a/log/logger.ts b/log/logger.ts index 4ce2c3614fc1..bf68f081b6c2 100644 --- a/log/logger.ts +++ b/log/logger.ts @@ -181,24 +181,13 @@ export class Logger { return this.#log(LogLevels.INFO, msg, ...args); } - /** @deprecated (will be removed after 0.214.0) Use {@linkcode warn} instead. */ - warning(msg: () => T, ...args: unknown[]): T | undefined; - /** @deprecated (will be removed after 0.214.0) Use {@linkcode warn} instead. */ - warning(msg: T extends GenericFunction ? never : T, ...args: unknown[]): T; - warning( - msg: (T extends GenericFunction ? never : T) | (() => T), - ...args: unknown[] - ): T | undefined { - return this.warn(msg as () => T, ...args); - } - warn(msg: () => T, ...args: unknown[]): T | undefined; warn(msg: T extends GenericFunction ? never : T, ...args: unknown[]): T; warn( msg: (T extends GenericFunction ? never : T) | (() => T), ...args: unknown[] ): T | undefined { - return this.#log(LogLevels.WARNING, msg, ...args); + return this.#log(LogLevels.WARN, msg, ...args); } error(msg: () => T, ...args: unknown[]): T | undefined; diff --git a/log/logger_test.ts b/log/logger_test.ts index dcb82e4d390b..ba1da7ad97ff 100644 --- a/log/logger_test.ts +++ b/log/logger_test.ts @@ -88,7 +88,7 @@ Deno.test("logFunctions", function () { assertEquals(handler.messages, [ "DEBUG foo", "INFO bar", - "WARNING baz", + "WARN baz", "ERROR boo", "CRITICAL doo", ]); @@ -97,14 +97,14 @@ Deno.test("logFunctions", function () { assertEquals(handler.messages, [ "INFO bar", - "WARNING baz", + "WARN baz", "ERROR boo", "CRITICAL doo", ]); - handler = doLog("WARNING"); + handler = doLog("WARN"); - assertEquals(handler.messages, ["WARNING baz", "ERROR boo", "CRITICAL doo"]); + assertEquals(handler.messages, ["WARN baz", "ERROR boo", "CRITICAL doo"]); handler = doLog("ERROR"); @@ -182,8 +182,8 @@ Deno.test( assertEquals(data5, 3); const data6: number = logger.warn(3, 1); assertEquals(data6, 3); - assertEquals(handler.messages[4], "WARNING 3"); - assertEquals(handler.messages[5], "WARNING 3"); + assertEquals(handler.messages[4], "WARN 3"); + assertEquals(handler.messages[5], "WARN 3"); // bigint const data7: bigint = logger.error(5n); @@ -222,8 +222,8 @@ Deno.test( assertEquals(data15, "abc"); const data16: string | undefined = logger.warn(fn, 1); assertEquals(data16, "abc"); - assertEquals(handler.messages[14], "WARNING abc"); - assertEquals(handler.messages[15], "WARNING abc"); + assertEquals(handler.messages[14], "WARN abc"); + assertEquals(handler.messages[15], "WARN abc"); // object const data17: { payload: string; other: number } = logger.error({ diff --git a/log/mod.ts b/log/mod.ts index 22b5d1ffa70a..bde30593cde5 100644 --- a/log/mod.ts +++ b/log/mod.ts @@ -148,7 +148,7 @@ * handlers: { * console: new log.ConsoleHandler("DEBUG"), * - * file: new log.FileHandler("WARNING", { + * file: new log.FileHandler("WARN", { * filename: "./log.txt", * // you can change format of output message using any keys in `LogRecord`. * formatter: (record) => `${record.levelName} ${record.msg}`, @@ -173,7 +173,7 @@ * * // get default logger. * logger = log.getLogger(); - * logger.debug("fizz"); // logs to `console`, because `file` handler requires "WARNING" level. + * logger.debug("fizz"); // logs to `console`, because `file` handler requires "WARN" level. * logger.warn(41256); // logs to both `console` and `file` handlers. * * // get custom logger @@ -477,33 +477,7 @@ export function info( return getLogger("default").info(msg, ...args); } -/** - * @deprecated (will be removed after 0.214.0) Use {@linkcode warn} instead. - * - * Log with warning level, using default logger. - */ -export function warning(msg: () => T, ...args: unknown[]): T | undefined; -/** - * @deprecated (will be removed after 0.214.0) Use {@linkcode warn} instead. - * - * Log with warning level, using default logger. - */ -export function warning( - msg: T extends GenericFunction ? never : T, - ...args: unknown[] -): T; -export function warning( - msg: (T extends GenericFunction ? never : T) | (() => T), - ...args: unknown[] -): T | undefined { - // Assist TS compiler with pass-through generic type - if (msg instanceof Function) { - return warn(msg, ...args); - } - return warn(msg, ...args); -} - -/** Log with warning level, using default logger. */ +/** Log with warn level, using default logger. */ export function warn(msg: () => T, ...args: unknown[]): T | undefined; export function warn( msg: T extends GenericFunction ? never : T, diff --git a/log/mod_test.ts b/log/mod_test.ts index c147c3eb47af..ab71c7259d9b 100644 --- a/log/mod_test.ts +++ b/log/mod_test.ts @@ -123,9 +123,9 @@ Deno.test({ assertEquals(testHandler.messages[2], "CRITICAL critical"); testHandler.messages = []; - logger.level = LogLevels.WARNING; - assertEquals(logger.levelName, "WARNING"); - assertEquals(logger.level, LogLevels.WARNING); + logger.level = LogLevels.WARN; + assertEquals(logger.levelName, "WARN"); + assertEquals(logger.level, LogLevels.WARN); logger.debug("debug2"); logger.error("error2"); diff --git a/log/rotating_file_handler_test.ts b/log/rotating_file_handler_test.ts index bb17a3fb7034..3d724edd6219 100644 --- a/log/rotating_file_handler_test.ts +++ b/log/rotating_file_handler_test.ts @@ -30,7 +30,7 @@ Deno.test({ new TextEncoder().encode("hello world"), ); - const fileHandler = new RotatingFileHandler("WARNING", { + const fileHandler = new RotatingFileHandler("WARN", { filename: LOG_FILE, maxBytes: 50, maxBackupCount: 3, @@ -56,7 +56,7 @@ Deno.test({ LOG_FILE + ".3", new TextEncoder().encode("hello world"), ); - using fileHandler = new RotatingFileHandler("WARNING", { + using fileHandler = new RotatingFileHandler("WARN", { filename: LOG_FILE, maxBytes: 50, maxBackupCount: 3, @@ -78,7 +78,7 @@ Deno.test({ Deno.test({ name: "RotatingFileHandler with first rollover, monitor step by step", async fn() { - using fileHandler = new RotatingFileHandler("WARNING", { + using fileHandler = new RotatingFileHandler("WARN", { filename: LOG_FILE, maxBytes: 25, maxBackupCount: 3, @@ -127,7 +127,7 @@ Deno.test({ Deno.test({ name: "RotatingFileHandler with first rollover, check all at once", async fn() { - const fileHandler = new RotatingFileHandler("WARNING", { + const fileHandler = new RotatingFileHandler("WARN", { filename: LOG_FILE, maxBytes: 25, maxBackupCount: 3, @@ -187,7 +187,7 @@ Deno.test({ new TextEncoder().encode("original log.3 file"), ); - const fileHandler = new RotatingFileHandler("WARNING", { + const fileHandler = new RotatingFileHandler("WARN", { filename: LOG_FILE, maxBytes: 2, maxBackupCount: 3, @@ -232,7 +232,7 @@ Deno.test({ fn() { assertThrows( () => { - const fileHandler = new RotatingFileHandler("WARNING", { + const fileHandler = new RotatingFileHandler("WARN", { filename: LOG_FILE, maxBytes: 0, maxBackupCount: 3, @@ -251,7 +251,7 @@ Deno.test({ fn() { assertThrows( () => { - const fileHandler = new RotatingFileHandler("WARNING", { + const fileHandler = new RotatingFileHandler("WARN", { filename: LOG_FILE, maxBytes: 50, maxBackupCount: 0, @@ -268,7 +268,7 @@ Deno.test({ Deno.test({ name: "RotatingFileHandler: rotate on byte length, not msg length", async fn() { - const fileHandler = new RotatingFileHandler("WARNING", { + const fileHandler = new RotatingFileHandler("WARN", { filename: LOG_FILE, maxBytes: 7, maxBackupCount: 1, diff --git a/log/test.ts b/log/test.ts index 874e85321af7..370651693a86 100644 --- a/log/test.ts +++ b/log/test.ts @@ -23,7 +23,7 @@ Deno.test("defaultHandlers", async function () { } = { DEBUG: log.debug, INFO: log.info, - WARNING: log.warn, + WARN: log.warn, ERROR: log.error, CRITICAL: log.critical, }; From 10f6763392a09bfa4f65fb6617da84c276fb2a31 Mon Sep 17 00:00:00 2001 From: Asher Gomez Date: Fri, 2 Feb 2024 11:37:35 +1100 Subject: [PATCH 2/2] update --- log/warn.ts | 26 -------------------------- 1 file changed, 26 deletions(-) diff --git a/log/warn.ts b/log/warn.ts index e5cad5c6f52f..01c65cf4b8a9 100644 --- a/log/warn.ts +++ b/log/warn.ts @@ -19,29 +19,3 @@ export function warn( } return getLogger("default").warn(msg, ...args); } - -/** - * @deprecated (will be removed after 0.214.0) Use {@linkcode warn} instead. - * - * Log with warning level, using default logger. - */ -export function warning(msg: () => T, ...args: unknown[]): T | undefined; -/** - * @deprecated (will be removed after 0.214.0) Use {@linkcode warn} instead. - * - * Log with warning level, using default logger. - */ -export function warning( - msg: T extends GenericFunction ? never : T, - ...args: unknown[] -): T; -export function warning( - msg: (T extends GenericFunction ? never : T) | (() => T), - ...args: unknown[] -): T | undefined { - // Assist TS compiler with pass-through generic type - if (msg instanceof Function) { - return warn(msg, ...args); - } - return warn(msg, ...args); -}