docs(log): improve logger.ts docs (#6176)

This commit is contained in:
Efe 2024-11-07 04:43:02 +01:00 committed by GitHub
parent 63fdf8d090
commit bf0ad522e8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 84 additions and 0 deletions

View File

@ -82,6 +82,7 @@ const ENTRY_POINTS = [
"../log/console_handler.ts",
"../log/formatters.ts",
"../log/get_logger.ts",
"../log/logger.ts",
"../media_types/mod.ts",
"../msgpack/mod.ts",
"../net/mod.ts",

View File

@ -22,15 +22,98 @@ export interface LogRecordOptions {
loggerName: string;
}
/**
* Configuration options for a logger instance.
*
* @example Usage
*
* ```ts
* import { ConsoleHandler, getLogger, setup, type LogConfig} from "@std/log";
* import { assert } from "@std/assert";
*
* const handler = new ConsoleHandler("INFO");
* const logConfig: LogConfig = {
* handlers: {
* default: handler,
* },
* loggers: {
* default: {
* level: "INFO",
* handlers: ["default"],
* },
* },
* }
* setup(logConfig);
* const logger = getLogger();
*
* assert(logger.handlers.at(0) instanceof ConsoleHandler);
* ```
*/
export class LoggerConfig {
/** The minimum log level for the logger.
*
* @example Usage
*
* ```ts
* import { ConsoleHandler, getLogger, setup, type LogConfig} from "@std/log";
* import { assert } from "@std/assert";
*
* const handler = new ConsoleHandler("INFO");
* const logConfig: LogConfig = {
* handlers: {
* default: handler,
* },
* loggers: {
* default: {
* level: "INFO",
* handlers: ["default"],
* },
* },
* }
* setup(logConfig);
* const logger = getLogger();
*
* assert(logger.handlers.at(0) instanceof ConsoleHandler);
* ```
*/
level?: LevelName;
/** A list of handler names attached to this logger.
*
* @example Usage
*
* ```ts
* import { ConsoleHandler, getLogger, setup, type LogConfig} from "@std/log";
* import { assert } from "@std/assert";
*
* const handler = new ConsoleHandler("INFO");
* const logConfig: LogConfig = {
* handlers: {
* default: handler,
* },
* loggers: {
* default: {
* level: "INFO",
* handlers: ["default"],
* },
* },
* }
* setup(logConfig);
* const logger = getLogger();
*
* assert(logger.handlers.at(0) instanceof ConsoleHandler);
* ``` */
handlers?: string[];
}
/**
* Configuration for logger setup.
*/
export interface LogConfig {
/** A dictionary of named handlers for logging. */
handlers?: {
[name: string]: BaseHandler;
};
/** A dictionary of named loggers and their configurations. */
loggers?: {
[name: string]: LoggerConfig;
};