docs(log): document warn module (#5973)

This commit is contained in:
Asher Gomez 2024-09-18 15:04:33 +10:00 committed by GitHub
parent 3b518076aa
commit 77eba7f042
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 50 additions and 1 deletions

View File

@ -70,6 +70,7 @@ const ENTRY_POINTS = [
"../io/mod.ts",
"../json/mod.ts",
"../jsonc/mod.ts",
"../log/warn.ts",
"../media_types/mod.ts",
"../msgpack/mod.ts",
"../net/mod.ts",

View File

@ -4,6 +4,7 @@ import { getLevelByName, getLevelName, LogLevels } from "./levels.ts";
import type { LevelName, LogLevel } from "./levels.ts";
import type { BaseHandler } from "./base_handler.ts";
/** Any function that can be called with any arguments and return any value. */
// deno-lint-ignore no-explicit-any
export type GenericFunction = (...args: any[]) => any;

View File

@ -4,8 +4,55 @@
import { getLogger } from "./get_logger.ts";
import type { GenericFunction } from "./logger.ts";
/** Log with warning level, using default logger. */
export type { GenericFunction };
/**
* Log at the warning level.
*
* This function is a pass-through to the default logger's `warn` method. By
* default, the default logger is configured to use {@linkcode console.log}.
*
* @template T The type of the message to log.
* @param msg The message to log.
* @param args Arguments to be formatted into the message.
* @returns The message that was logged.
*
* @example Usage
* ```ts
* import { warn } from "@std/log/warn";
* import { assertEquals } from "@std/assert/equals";
*
* assertEquals(warn("This is a warning message."), "This is a warning message.");
* // Prints: "WARN This is a warning message."
*
* assertEquals(warn(() => "This is a warning message."), "This is a warning message.");
* // Prints: "WARN This is a warning message."
* ```
*/
export function warn<T>(msg: () => T, ...args: unknown[]): T | undefined;
/**
* Log at the warning level.
*
* This function is a pass-through to the default logger's `warn` method. By
* default, the default logger is configured to use {@linkcode console.log}.
*
* @template T The type of the message to log.
* @param msg The message to log.
* @param args Arguments to be formatted into the message.
* @returns The message that was logged.
*
* @example Usage
* ```ts
* import { warn } from "@std/log/warn";
* import { assertEquals } from "@std/assert/equals";
*
* assertEquals(warn("This is a warning message."), "This is a warning message.");
* // Prints: "WARN This is a warning message."
*
* assertEquals(warn(() => "This is a warning message."), "This is a warning message.");
* // Prints: "WARN This is a warning message."
* ```
*/
export function warn<T>(
msg: T extends GenericFunction ? never : T,
...args: unknown[]