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

deprecation(log): rename warning() to warn() #4117

Merged
merged 19 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
11 changes: 11 additions & 0 deletions log/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,22 @@
return this.#_log(LogLevels.INFO, msg, ...args);
}

/** @deprecated (will be removed after 0.214.0) Use {@linkcode warn} instead. */
warning<T>(msg: () => T, ...args: unknown[]): T | undefined;
/** @deprecated (will be removed after 0.214.0) Use {@linkcode warn} instead. */
warning<T>(msg: T extends GenericFunction ? never : T, ...args: unknown[]): T;
timreichen marked this conversation as resolved.
Show resolved Hide resolved
warning<T>(
msg: (T extends GenericFunction ? never : T) | (() => T),
...args: unknown[]
): T | undefined {
return this.warn(msg as () => T, ...args);
}

Check warning on line 179 in log/logger.ts

View check run for this annotation

Codecov / codecov/patch

log/logger.ts#L177-L179

Added lines #L177 - L179 were not covered by tests

warn<T>(msg: () => T, ...args: unknown[]): T | undefined;
warn<T>(msg: T extends GenericFunction ? never : T, ...args: unknown[]): T;
warn<T>(
msg: (T extends GenericFunction ? never : T) | (() => T),
...args: unknown[]
): T | undefined {
return this.#_log(LogLevels.WARNING, msg, ...args);
timreichen marked this conversation as resolved.
Show resolved Hide resolved
}
Expand Down
12 changes: 6 additions & 6 deletions log/logger_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ Deno.test("logFunctions", function () {
const logger = new Logger("default", level, { handlers: [handler] });
const debugData = logger.debug("foo");
const infoData = logger.info("bar");
const warningData = logger.warning("baz");
const warnData = logger.warn("baz");
const errorData = logger.error("boo");
const criticalData = logger.critical("doo");
assertEquals(debugData, "foo");
assertEquals(infoData, "bar");
assertEquals(warningData, "baz");
assertEquals(warnData, "baz");
assertEquals(errorData, "boo");
assertEquals(criticalData, "doo");
return handler;
Expand Down Expand Up @@ -177,9 +177,9 @@ Deno.test(
assertEquals(handler.messages[3], "INFO null");

// number
const data5: number = logger.warning(3);
const data5: number = logger.warn(3);
assertEquals(data5, 3);
const data6: number = logger.warning(3, 1);
const data6: number = logger.warn(3, 1);
assertEquals(data6, 3);
assertEquals(handler.messages[4], "WARNING 3");
assertEquals(handler.messages[5], "WARNING 3");
Expand Down Expand Up @@ -217,9 +217,9 @@ Deno.test(
assertEquals(handler.messages[13], "INFO Symbol(a)");

// function
const data15: string | undefined = logger.warning(fn);
const data15: string | undefined = logger.warn(fn);
assertEquals(data15, "abc");
const data16: string | undefined = logger.warning(fn, 1);
const data16: string | undefined = logger.warn(fn, 1);
assertEquals(data16, "abc");
assertEquals(handler.messages[14], "WARNING abc");
assertEquals(handler.messages[15], "WARNING abc");
Expand Down
36 changes: 31 additions & 5 deletions log/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
* // additional logger configurations. You can log any data type.
* log.debug("Hello world");
* log.info(123456);
* log.warning(true);
* log.warn(true);
* log.error({ foo: "bar", fizz: "bazz" });
* log.critical("500 Internal server error");
*
Expand Down Expand Up @@ -174,7 +174,7 @@
* // get default logger.
* logger = log.getLogger();
* logger.debug("fizz"); // logs to `console`, because `file` handler requires "WARNING" level.
* logger.warning(41256); // logs to both `console` and `file` handlers.
* logger.warn(41256); // logs to both `console` and `file` handlers.
*
* // get custom logger
* logger = log.getLogger("tasks");
Expand Down Expand Up @@ -498,8 +498,17 @@
return getLogger("default").info(msg, ...args);
}

/** Log with warning level, using default logger. */
/**
* @deprecated (will be removed after 0.214.0) Use {@linkcode warn} instead.
*
* Log with warning level, using default logger.
*/
export function warning<T>(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<T>(
timreichen marked this conversation as resolved.
Show resolved Hide resolved
msg: T extends GenericFunction ? never : T,
...args: unknown[]
Expand All @@ -510,9 +519,26 @@
): T | undefined {
// Assist TS compiler with pass-through generic type
if (msg instanceof Function) {
return getLogger("default").warning(msg, ...args);
return warn(msg, ...args);
}
return warn(msg, ...args);
}

Check warning on line 525 in log/mod.ts

View check run for this annotation

Codecov / codecov/patch

log/mod.ts#L522-L525

Added lines #L522 - L525 were not covered by tests

/** Log with warning level, using default logger. */
export function warn<T>(msg: () => T, ...args: unknown[]): T | undefined;
export function warn<T>(
msg: T extends GenericFunction ? never : T,
...args: unknown[]
): T;
export function warn<T>(
msg: (T extends GenericFunction ? never : T) | (() => T),
...args: unknown[]
): T | undefined {
// Assist TS compiler with pass-through generic type
if (msg instanceof Function) {
return getLogger("default").warn(msg, ...args);
}
return getLogger("default").warning(msg, ...args);
return getLogger("default").warn(msg, ...args);
}

/** Log with error level, using default logger. */
Expand Down
10 changes: 5 additions & 5 deletions log/mod_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
Logger,
LogLevels,
setup,
warning,
warn,
} from "./mod.ts";
import { BaseHandler } from "./handlers.ts";

Expand Down Expand Up @@ -41,8 +41,8 @@ Deno.test("default loggers work as expected", function () {
const debugResolver: string | undefined = debug(() => "foo");
const infoData: number = info(456, 1, 2, 3);
const infoResolver: boolean | undefined = info(() => true);
const warningData: symbol = warning(sym);
const warningResolver: null | undefined = warning(() => null);
const warnData: symbol = warn(sym);
const warnResolver: null | undefined = warn(() => null);
const errorData: undefined = error(undefined, 1, 2, 3);
const errorResolver: bigint | undefined = error(() => 5n);
const criticalData: string = critical("foo");
Expand All @@ -51,8 +51,8 @@ Deno.test("default loggers work as expected", function () {
assertEquals(debugResolver, undefined);
assertEquals(infoData, 456);
assertEquals(infoResolver, true);
assertEquals(warningData, sym);
assertEquals(warningResolver, null);
assertEquals(warnData, sym);
assertEquals(warnResolver, null);
assertEquals(errorData, undefined);
assertEquals(errorResolver, 5n);
assertEquals(criticalData, "foo");
Expand Down
2 changes: 1 addition & 1 deletion log/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Deno.test("defaultHandlers", async function () {
} = {
DEBUG: log.debug,
INFO: log.info,
WARNING: log.warning,
WARNING: log.warn,
timreichen marked this conversation as resolved.
Show resolved Hide resolved
ERROR: log.error,
CRITICAL: log.critical,
};
Expand Down