From bf0ad522e873866764632b84f0e8460855f0d7e6 Mon Sep 17 00:00:00 2001 From: Efe Date: Thu, 7 Nov 2024 04:43:02 +0100 Subject: [PATCH] docs(log): improve logger.ts docs (#6176) --- _tools/check_docs.ts | 1 + log/logger.ts | 83 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+) diff --git a/_tools/check_docs.ts b/_tools/check_docs.ts index e2457d645..10bff1b71 100644 --- a/_tools/check_docs.ts +++ b/_tools/check_docs.ts @@ -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", diff --git a/log/logger.ts b/log/logger.ts index 8e31e4ebe..e7da2c7d8 100644 --- a/log/logger.ts +++ b/log/logger.ts @@ -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; };