Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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: {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We generally prefer 2-space indent here, but not a big deal

* 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