Skip to content

Commit

Permalink
deprecation(log): rename warning() to warn() (#4117)
Browse files Browse the repository at this point in the history
* initial commit

* Update log/logger.ts

Co-authored-by: Asher Gomez <[email protected]>

* replace WARNING with WARN

* update

* refactor(cli): make `Spinner` constructor options more readable (#4091)

* initial commit

* update

* docs(testing): fix assertion deprecation notices (#4122)

* refactor(assert): remove `void` return types (#4124)

* fix(http): punt removal version of `unstable_cookie_map.ts` (#4125)

* chore: ignore `/docs` in license checker tool (#4123)

* deprecation(semver): rename `rangeFormat()` to `formatRange()` (#4090)

Co-authored-by: Asher Gomez <[email protected]>

* refactor(archive): prepare for `noUncheckedIndexedAccess` (#4110)

* refactor(archive): prepare for noUncheckedIndexedAccess

* adjust test to handle new TarHeader requirements

* revert WARNING

---------

Co-authored-by: Asher Gomez <[email protected]>
Co-authored-by: Simon Holloway <[email protected]>
  • Loading branch information
3 people authored Jan 11, 2024
1 parent a1877c8 commit f5b6774
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 17 deletions.
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 @@ export class Logger {
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;
warning<T>(
msg: (T extends GenericFunction ? never : T) | (() => T),
...args: unknown[]
): T | undefined {
return this.warn(msg as () => T, ...args);
}

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);
}
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 @@ export function info<T>(
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>(
msg: T extends GenericFunction ? never : T,
...args: unknown[]
Expand All @@ -510,9 +519,26 @@ export function warning<T>(
): 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);
}

/** 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,
ERROR: log.error,
CRITICAL: log.critical,
};
Expand Down

0 comments on commit f5b6774

Please sign in to comment.