Skip to content

Commit

Permalink
docs(log): document logger.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
efekrskl committed Nov 6, 2024
1 parent 63fdf8d commit f855302
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
1 change: 1 addition & 0 deletions _tools/check_docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
83 changes: 83 additions & 0 deletions log/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
* ```
*/

Check warning on line 78 in log/logger.ts

View check run for this annotation

Codecov / codecov/patch

log/logger.ts#L78

Added line #L78 was not covered by tests
level?: LevelName;
/** A list of handler names attached to this logger.

Check warning on line 80 in log/logger.ts

View check run for this annotation

Codecov / codecov/patch

log/logger.ts#L80

Added line #L80 was not covered by tests
*
* @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);
* ``` */

Check warning on line 104 in log/logger.ts

View check run for this annotation

Codecov / codecov/patch

log/logger.ts#L104

Added line #L104 was not covered by tests
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;
};
Expand Down

0 comments on commit f855302

Please sign in to comment.