@logtape/adaptor-winston 1.0.0-dev.258 → 1.0.0-dev.262
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/deno.json +1 -1
- package/dist/mod.cjs +4 -0
- package/dist/mod.js +4 -0
- package/dist/mod.js.map +1 -1
- package/mod.ts +5 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -56,7 +56,7 @@ For custom winston loggers or configuration options, see the [Usage](#usage) sec
|
|
|
56
56
|
Usage
|
|
57
57
|
-----
|
|
58
58
|
|
|
59
|
-
### Using the install() function
|
|
59
|
+
### Using the `install()` function
|
|
60
60
|
|
|
61
61
|
If you need a custom winston logger or configuration options, you can use
|
|
62
62
|
the `install()` function:
|
package/deno.json
CHANGED
package/dist/mod.cjs
CHANGED
|
@@ -109,6 +109,10 @@ function install(loggerOrOptions, options = {}) {
|
|
|
109
109
|
(0, __logtape_logtape.configureSync)({
|
|
110
110
|
sinks: { winston: getWinstonSink(logger, sinkOptions) },
|
|
111
111
|
loggers: [{
|
|
112
|
+
category: ["logtape", "meta"],
|
|
113
|
+
sinks: ["winston"],
|
|
114
|
+
lowestLevel: "warning"
|
|
115
|
+
}, {
|
|
112
116
|
category: [],
|
|
113
117
|
sinks: ["winston"]
|
|
114
118
|
}]
|
package/dist/mod.js
CHANGED
|
@@ -108,6 +108,10 @@ function install(loggerOrOptions, options = {}) {
|
|
|
108
108
|
configureSync({
|
|
109
109
|
sinks: { winston: getWinstonSink(logger, sinkOptions) },
|
|
110
110
|
loggers: [{
|
|
111
|
+
category: ["logtape", "meta"],
|
|
112
|
+
sinks: ["winston"],
|
|
113
|
+
lowestLevel: "warning"
|
|
114
|
+
}, {
|
|
111
115
|
category: [],
|
|
112
116
|
sinks: ["winston"]
|
|
113
117
|
}]
|
package/dist/mod.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.js","names":["DEFAULT_LEVELS_MAP: Readonly<Record<LogLevel, keyof Logger>>","logger: Logger","options: WinstonSinkOptions","category: Required<CategoryOptions> | undefined","record: LogRecord","loggerOrOptions?: Logger | WinstonSinkOptions","sinkOptions: WinstonSinkOptions"],"sources":["../mod.ts"],"sourcesContent":["/**\n * A winston adapter for LogTape logging library.\n *\n * This module provides functionality to integrate LogTape with winston,\n * allowing LogTape logs to be forwarded to winston loggers while maintaining\n * structured logging capabilities and category information.\n *\n * @example\n * ```typescript\n * import { configure } from \"@logtape/logtape\";\n * import winston from \"winston\";\n * import { getWinstonSink } from \"@logtape/adaptor-winston\";\n *\n * const winstonLogger = winston.createLogger({\n * level: \"info\",\n * format: winston.format.json(),\n * transports: [new winston.transports.Console()]\n * });\n *\n * await configure({\n * sinks: {\n * winston: getWinstonSink(winstonLogger)\n * },\n * loggers: [\n * { category: \"myapp\", sinks: [\"winston\"] }\n * ]\n * });\n * ```\n *\n * @module\n * @since 1.0.0\n */\nimport {\n configureSync,\n type LogLevel,\n type LogRecord,\n type Sink,\n} from \"@logtape/logtape\";\nimport winston, { type LeveledLogMethod } from \"winston\";\nimport { inspect } from \"node:util\";\n\n/**\n * Logger interface for Winston-compatible loggers.\n * @since 1.0.0\n */\nexport interface Logger {\n error: LeveledLogMethod;\n warn: LeveledLogMethod;\n info: LeveledLogMethod;\n http: LeveledLogMethod;\n verbose: LeveledLogMethod;\n debug: LeveledLogMethod;\n silly: LeveledLogMethod;\n}\n\n/**\n * Configuration options for the winston sink.\n *\n * @example Basic usage with default options\n * ```typescript\n * const sink = getWinstonSink(winstonLogger);\n * ```\n *\n * @example Custom level mapping\n * ```typescript\n * const sink = getWinstonSink(winstonLogger, {\n * levelsMap: {\n * \"trace\": \"debug\",\n * \"debug\": \"debug\",\n * \"info\": \"info\",\n * \"warning\": \"warn\",\n * \"error\": \"error\",\n * \"fatal\": \"error\"\n * }\n * });\n * ```\n *\n * @example Custom category formatting\n * ```typescript\n * const sink = getWinstonSink(winstonLogger, {\n * category: {\n * separator: \".\",\n * position: \"start\",\n * decorator: \"[]\"\n * }\n * });\n * ```\n *\n * @since 1.0.0\n */\nexport interface WinstonSinkOptions {\n /**\n * Mapping between LogTape log levels and winston log levels.\n *\n * By default, LogTape levels are mapped as follows:\n *\n * - `trace` → `silly`\n * - `debug` → `debug`\n * - `info` → `info`\n * - `warning` → `warn`\n * - `error` → `error`\n * - `fatal` → `error`\n */\n readonly levelsMap?: Readonly<Record<LogLevel, keyof Logger>>;\n\n /**\n * Configuration for how LogTape categories are handled in winston logs.\n *\n * - `false` or `undefined`: Categories are not included in the log message\n * - `true`: Categories are included with default formatting (\":\" decorator at start)\n * - `CategoryOptions`: Custom category formatting configuration\n *\n * @default undefined\n */\n readonly category?: boolean | CategoryOptions;\n\n /**\n * Custom formatter for interpolated values in log messages.\n *\n * This function is used to convert values that are interpolated into\n * log messages (e.g., the `name` in\n * `logger.info(\"Hello, {name}!\", { name: \"world\" })`).\n *\n * @param value The value to format\n * @returns A string representation of the value\n * @default `inspect` (from `node:util` module)\n */\n readonly valueFormatter?: (value: unknown) => string;\n}\n\n/**\n * Configuration options for formatting LogTape categories in winston log messages.\n *\n * Categories in LogTape represent a hierarchical namespace for loggers\n * (e.g., [\"myapp\", \"database\", \"connection\"]). This interface controls\n * how these categories are formatted when included in winston log messages.\n *\n * @example Default formatting\n * ```typescript\n * // With category [\"myapp\", \"db\"] and default options:\n * // Output: \"myapp·db: User logged in\"\n * const options: CategoryOptions = {};\n * ```\n *\n * @example Custom separator and decorator\n * ```typescript\n * // With category [\"myapp\", \"db\"] and custom options:\n * // Output: \"[myapp.db] User logged in\"\n * const options: CategoryOptions = {\n * separator: \".\",\n * decorator: \"[]\"\n * };\n * ```\n *\n * @example Category at end\n * ```typescript\n * // With category [\"myapp\", \"db\"] and position at end:\n * // Output: \"User logged in: myapp·db\"\n * const options: CategoryOptions = {\n * position: \"end\"\n * };\n * ```\n *\n * @since 1.0.0\n */\nexport interface CategoryOptions {\n /**\n * The separator used to join category parts when multiple categories exist.\n * @default \"·\"\n */\n readonly separator?: string;\n\n /**\n * Where to position the category in the log message.\n * - `\"start\"`: Category appears at the beginning of the message\n * - `\"end\"`: Category appears at the end of the message\n * @default \"start\"\n */\n readonly position?: \"start\" | \"end\";\n\n /**\n * The decorator used to format the category in the log message.\n * - `\"[]\"`: [category] format\n * - `\"()\"`: (category) format\n * - `\"<>\"`: <category> format\n * - `\"{}\"`: {category} format\n * - `\":\"`: category: format\n * - `\"-\"`: category - format\n * - `\"|\"`: category | format\n * - `\"/\"`: category / format\n * - `\"\"`: category format (no decoration)\n * @default \":\"\n */\n readonly decorator?: \"[]\" | \"()\" | \"<>\" | \"{}\" | \":\" | \"-\" | \"|\" | \"/\" | \"\";\n}\n\nconst DEFAULT_LEVELS_MAP: Readonly<Record<LogLevel, keyof Logger>> = {\n \"trace\": \"silly\",\n \"debug\": \"debug\",\n \"info\": \"info\",\n \"warning\": \"warn\",\n \"error\": \"error\",\n \"fatal\": \"error\",\n};\n\n/**\n * Creates a LogTape sink that forwards log records to a winston logger.\n *\n * This function creates a sink function that can be used with LogTape's\n * configuration system. The sink will format LogTape log records and\n * forward them to the provided winston logger instance.\n *\n * @example Basic usage\n * ```typescript\n * import winston from \"winston\";\n * import { configure } from \"@logtape/logtape\";\n * import { getWinstonSink } from \"@logtape/adaptor-winston\";\n *\n * const winstonLogger = winston.createLogger({\n * level: \"info\",\n * format: winston.format.combine(\n * winston.format.timestamp(),\n * winston.format.json()\n * ),\n * transports: [new winston.transports.Console()]\n * });\n *\n * await configure({\n * sinks: {\n * winston: getWinstonSink(winstonLogger)\n * },\n * loggers: [\n * { category: [\"myapp\"], sinks: [\"winston\"] }\n * ]\n * });\n * ```\n *\n * @example With custom options\n * ```typescript\n * const sink = getWinstonSink(winstonLogger, {\n * category: {\n * separator: \".\",\n * position: \"start\",\n * decorator: \"[]\"\n * },\n * levelsMap: {\n * \"trace\": \"debug\", // Map trace to debug instead of silly\n * \"debug\": \"debug\",\n * \"info\": \"info\",\n * \"warning\": \"warn\",\n * \"error\": \"error\",\n * \"fatal\": \"error\"\n * }\n * });\n * ```\n *\n * @param logger The winston logger instance to forward logs to. Must implement\n * the Logger interface with error, warn, info, http, verbose,\n * debug, and silly methods.\n * @param options Configuration options for the sink behavior.\n * @returns A sink function that can be used with LogTape's configure() function.\n * @since 1.0.0\n */\nexport function getWinstonSink(\n logger: Logger,\n options: WinstonSinkOptions = {},\n): Sink {\n const { levelsMap = DEFAULT_LEVELS_MAP, valueFormatter = inspect } = options;\n const categoryOptions = !options.category\n ? undefined\n : typeof options.category === \"object\"\n ? options.category\n : {};\n const category: Required<CategoryOptions> | undefined =\n categoryOptions == null ? undefined : {\n separator: categoryOptions.separator ?? \"·\",\n position: categoryOptions.position ?? \"start\",\n decorator: categoryOptions.decorator ?? \":\",\n };\n\n return (record: LogRecord) => {\n const level = levelsMap[record.level];\n let message = \"\";\n if (category?.position === \"start\" && record.category.length > 0) {\n const joinedCategory = record.category.join(category.separator);\n message += category.decorator === \"[]\"\n ? `[${joinedCategory}] `\n : category.decorator === \"()\"\n ? `(${joinedCategory}) `\n : category.decorator === \"<>\"\n ? `<${joinedCategory}> `\n : category.decorator === \"{}\"\n ? `{${joinedCategory}} `\n : category.decorator === \":\"\n ? `${joinedCategory}: `\n : category.decorator === \"-\"\n ? `${joinedCategory} - `\n : category.decorator === \"|\"\n ? `${joinedCategory} | `\n : category.decorator === \"/\"\n ? `${joinedCategory} / `\n : `${joinedCategory} `;\n }\n for (let i = 0; i < record.message.length; i += 2) {\n message += record.message[i];\n if (i + 1 < record.message.length) {\n message += valueFormatter(record.message[i + 1]);\n }\n }\n if (category?.position === \"end\" && record.category.length > 0) {\n const joinedCategory = record.category.join(category.separator);\n message += category.decorator === \"[]\"\n ? ` [${joinedCategory}]`\n : category.decorator === \"()\"\n ? ` (${joinedCategory})`\n : category.decorator === \"<>\"\n ? ` <${joinedCategory}>`\n : category.decorator === \"{}\"\n ? ` {${joinedCategory}}`\n : category.decorator === \":\"\n ? `: ${joinedCategory}`\n : category.decorator === \"-\"\n ? ` - ${joinedCategory}`\n : category.decorator === \"|\"\n ? ` | ${joinedCategory}`\n : category.decorator === \"/\"\n ? ` / ${joinedCategory}`\n : ` ${joinedCategory}`;\n }\n logger[level](message, record.properties);\n };\n}\n\n/**\n * Automatically configures LogTape to route all logs to a winston logger.\n *\n * This is a convenience function that automatically sets up LogTape to forward\n * all log records to a winston logger instance. By default, it uses winston's\n * default logger, but you can provide a custom logger as the first parameter.\n *\n * @param logger The winston logger instance to use.\n * @param options Configuration options for the winston sink behavior.\n *\n * @example Basic auto-configuration with default logger\n * ```typescript\n * import { install } from \"@logtape/adaptor-winston\";\n *\n * // Automatically route all LogTape logs to winston's default logger\n * install();\n *\n * // Now any LogTape-enabled library will log through winston\n * import { getLogger } from \"@logtape/logtape\";\n * const logger = getLogger(\"my-app\");\n * logger.info(\"This will be logged through winston\");\n * ```\n *\n * @example Auto-configuration with custom winston logger\n * ```typescript\n * import winston from \"winston\";\n * import { install } from \"@logtape/adaptor-winston\";\n *\n * const customLogger = winston.createLogger({\n * level: \"info\",\n * format: winston.format.combine(\n * winston.format.timestamp(),\n * winston.format.json()\n * ),\n * transports: [\n * new winston.transports.Console(),\n * new winston.transports.File({ filename: \"app.log\" })\n * ]\n * });\n *\n * // Install with custom logger\n * install(customLogger);\n * ```\n *\n * @example Auto-configuration with custom options\n * ```typescript\n * import { install } from \"@logtape/adaptor-winston\";\n *\n * install(undefined, {\n * category: {\n * position: \"start\",\n * decorator: \"[]\",\n * separator: \".\"\n * },\n * levelsMap: {\n * \"trace\": \"debug\" // Map LogTape trace to winston debug\n * }\n * });\n * ```\n *\n * @example Custom logger with custom options\n * ```typescript\n * import winston from \"winston\";\n * import { install } from \"@logtape/adaptor-winston\";\n *\n * const customLogger = winston.createLogger({\n * transports: [new winston.transports.Console()]\n * });\n *\n * install(customLogger, {\n * category: { position: \"start\", decorator: \"[]\" }\n * });\n * ```\n *\n * @since 1.0.0\n */\nexport function install(\n logger: Logger,\n options?: WinstonSinkOptions,\n): void;\n\n/**\n * Configures LogTape to route all logs to winston's default logger.\n *\n * @param options Optional configuration for the winston sink behavior.\n * @since 1.0.0\n */\nexport function install(\n options?: WinstonSinkOptions,\n): void;\n\nexport function install(\n loggerOrOptions?: Logger | WinstonSinkOptions,\n options: WinstonSinkOptions = {},\n): void {\n let logger: Logger;\n let sinkOptions: WinstonSinkOptions;\n\n // Handle overloaded parameters\n if (\n loggerOrOptions && (\"error\" in loggerOrOptions || \"info\" in loggerOrOptions)\n ) {\n // First parameter is a Logger\n logger = loggerOrOptions as Logger;\n sinkOptions = options;\n } else {\n // First parameter is WinstonSinkOptions or undefined\n logger = winston;\n sinkOptions = (loggerOrOptions as WinstonSinkOptions) || {};\n }\n\n configureSync({\n sinks: {\n winston: getWinstonSink(logger, sinkOptions),\n },\n loggers: [\n { category: [], sinks: [\"winston\"] },\n ],\n });\n}\n"],"mappings":";;;;;AAoMA,MAAMA,qBAA+D;CACnE,SAAS;CACT,SAAS;CACT,QAAQ;CACR,WAAW;CACX,SAAS;CACT,SAAS;AACV;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4DD,SAAgB,eACdC,QACAC,UAA8B,CAAE,GAC1B;CACN,MAAM,EAAE,YAAY,oBAAoB,iBAAiB,SAAS,GAAG;CACrE,MAAM,mBAAmB,QAAQ,2BAEtB,QAAQ,aAAa,WAC5B,QAAQ,WACR,CAAE;CACN,MAAMC,WACJ,mBAAmB,gBAAmB;EACpC,WAAW,gBAAgB,aAAa;EACxC,UAAU,gBAAgB,YAAY;EACtC,WAAW,gBAAgB,aAAa;CACzC;AAEH,QAAO,CAACC,WAAsB;EAC5B,MAAM,QAAQ,UAAU,OAAO;EAC/B,IAAI,UAAU;AACd,MAAI,UAAU,aAAa,WAAW,OAAO,SAAS,SAAS,GAAG;GAChE,MAAM,iBAAiB,OAAO,SAAS,KAAK,SAAS,UAAU;AAC/D,cA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,SAAS,CACP;GAAE,UAAU,CAAE;GAAE,OAAO,CAAC,SAAU;EAAE,CACrC;CACF,EAAC;AACH"}
|
|
1
|
+
{"version":3,"file":"mod.js","names":["DEFAULT_LEVELS_MAP: Readonly<Record<LogLevel, keyof Logger>>","logger: Logger","options: WinstonSinkOptions","category: Required<CategoryOptions> | undefined","record: LogRecord","loggerOrOptions?: Logger | WinstonSinkOptions","sinkOptions: WinstonSinkOptions"],"sources":["../mod.ts"],"sourcesContent":["/**\n * A winston adapter for LogTape logging library.\n *\n * This module provides functionality to integrate LogTape with winston,\n * allowing LogTape logs to be forwarded to winston loggers while maintaining\n * structured logging capabilities and category information.\n *\n * @example\n * ```typescript\n * import { configure } from \"@logtape/logtape\";\n * import winston from \"winston\";\n * import { getWinstonSink } from \"@logtape/adaptor-winston\";\n *\n * const winstonLogger = winston.createLogger({\n * level: \"info\",\n * format: winston.format.json(),\n * transports: [new winston.transports.Console()]\n * });\n *\n * await configure({\n * sinks: {\n * winston: getWinstonSink(winstonLogger)\n * },\n * loggers: [\n * { category: \"myapp\", sinks: [\"winston\"] }\n * ]\n * });\n * ```\n *\n * @module\n * @since 1.0.0\n */\nimport {\n configureSync,\n type LogLevel,\n type LogRecord,\n type Sink,\n} from \"@logtape/logtape\";\nimport winston, { type LeveledLogMethod } from \"winston\";\nimport { inspect } from \"node:util\";\n\n/**\n * Logger interface for Winston-compatible loggers.\n * @since 1.0.0\n */\nexport interface Logger {\n error: LeveledLogMethod;\n warn: LeveledLogMethod;\n info: LeveledLogMethod;\n http: LeveledLogMethod;\n verbose: LeveledLogMethod;\n debug: LeveledLogMethod;\n silly: LeveledLogMethod;\n}\n\n/**\n * Configuration options for the winston sink.\n *\n * @example Basic usage with default options\n * ```typescript\n * const sink = getWinstonSink(winstonLogger);\n * ```\n *\n * @example Custom level mapping\n * ```typescript\n * const sink = getWinstonSink(winstonLogger, {\n * levelsMap: {\n * \"trace\": \"debug\",\n * \"debug\": \"debug\",\n * \"info\": \"info\",\n * \"warning\": \"warn\",\n * \"error\": \"error\",\n * \"fatal\": \"error\"\n * }\n * });\n * ```\n *\n * @example Custom category formatting\n * ```typescript\n * const sink = getWinstonSink(winstonLogger, {\n * category: {\n * separator: \".\",\n * position: \"start\",\n * decorator: \"[]\"\n * }\n * });\n * ```\n *\n * @since 1.0.0\n */\nexport interface WinstonSinkOptions {\n /**\n * Mapping between LogTape log levels and winston log levels.\n *\n * By default, LogTape levels are mapped as follows:\n *\n * - `trace` → `silly`\n * - `debug` → `debug`\n * - `info` → `info`\n * - `warning` → `warn`\n * - `error` → `error`\n * - `fatal` → `error`\n */\n readonly levelsMap?: Readonly<Record<LogLevel, keyof Logger>>;\n\n /**\n * Configuration for how LogTape categories are handled in winston logs.\n *\n * - `false` or `undefined`: Categories are not included in the log message\n * - `true`: Categories are included with default formatting (\":\" decorator at start)\n * - `CategoryOptions`: Custom category formatting configuration\n *\n * @default undefined\n */\n readonly category?: boolean | CategoryOptions;\n\n /**\n * Custom formatter for interpolated values in log messages.\n *\n * This function is used to convert values that are interpolated into\n * log messages (e.g., the `name` in\n * `logger.info(\"Hello, {name}!\", { name: \"world\" })`).\n *\n * @param value The value to format\n * @returns A string representation of the value\n * @default `inspect` (from `node:util` module)\n */\n readonly valueFormatter?: (value: unknown) => string;\n}\n\n/**\n * Configuration options for formatting LogTape categories in winston log messages.\n *\n * Categories in LogTape represent a hierarchical namespace for loggers\n * (e.g., [\"myapp\", \"database\", \"connection\"]). This interface controls\n * how these categories are formatted when included in winston log messages.\n *\n * @example Default formatting\n * ```typescript\n * // With category [\"myapp\", \"db\"] and default options:\n * // Output: \"myapp·db: User logged in\"\n * const options: CategoryOptions = {};\n * ```\n *\n * @example Custom separator and decorator\n * ```typescript\n * // With category [\"myapp\", \"db\"] and custom options:\n * // Output: \"[myapp.db] User logged in\"\n * const options: CategoryOptions = {\n * separator: \".\",\n * decorator: \"[]\"\n * };\n * ```\n *\n * @example Category at end\n * ```typescript\n * // With category [\"myapp\", \"db\"] and position at end:\n * // Output: \"User logged in: myapp·db\"\n * const options: CategoryOptions = {\n * position: \"end\"\n * };\n * ```\n *\n * @since 1.0.0\n */\nexport interface CategoryOptions {\n /**\n * The separator used to join category parts when multiple categories exist.\n * @default \"·\"\n */\n readonly separator?: string;\n\n /**\n * Where to position the category in the log message.\n * - `\"start\"`: Category appears at the beginning of the message\n * - `\"end\"`: Category appears at the end of the message\n * @default \"start\"\n */\n readonly position?: \"start\" | \"end\";\n\n /**\n * The decorator used to format the category in the log message.\n * - `\"[]\"`: [category] format\n * - `\"()\"`: (category) format\n * - `\"<>\"`: <category> format\n * - `\"{}\"`: {category} format\n * - `\":\"`: category: format\n * - `\"-\"`: category - format\n * - `\"|\"`: category | format\n * - `\"/\"`: category / format\n * - `\"\"`: category format (no decoration)\n * @default \":\"\n */\n readonly decorator?: \"[]\" | \"()\" | \"<>\" | \"{}\" | \":\" | \"-\" | \"|\" | \"/\" | \"\";\n}\n\nconst DEFAULT_LEVELS_MAP: Readonly<Record<LogLevel, keyof Logger>> = {\n \"trace\": \"silly\",\n \"debug\": \"debug\",\n \"info\": \"info\",\n \"warning\": \"warn\",\n \"error\": \"error\",\n \"fatal\": \"error\",\n};\n\n/**\n * Creates a LogTape sink that forwards log records to a winston logger.\n *\n * This function creates a sink function that can be used with LogTape's\n * configuration system. The sink will format LogTape log records and\n * forward them to the provided winston logger instance.\n *\n * @example Basic usage\n * ```typescript\n * import winston from \"winston\";\n * import { configure } from \"@logtape/logtape\";\n * import { getWinstonSink } from \"@logtape/adaptor-winston\";\n *\n * const winstonLogger = winston.createLogger({\n * level: \"info\",\n * format: winston.format.combine(\n * winston.format.timestamp(),\n * winston.format.json()\n * ),\n * transports: [new winston.transports.Console()]\n * });\n *\n * await configure({\n * sinks: {\n * winston: getWinstonSink(winstonLogger)\n * },\n * loggers: [\n * { category: [\"myapp\"], sinks: [\"winston\"] }\n * ]\n * });\n * ```\n *\n * @example With custom options\n * ```typescript\n * const sink = getWinstonSink(winstonLogger, {\n * category: {\n * separator: \".\",\n * position: \"start\",\n * decorator: \"[]\"\n * },\n * levelsMap: {\n * \"trace\": \"debug\", // Map trace to debug instead of silly\n * \"debug\": \"debug\",\n * \"info\": \"info\",\n * \"warning\": \"warn\",\n * \"error\": \"error\",\n * \"fatal\": \"error\"\n * }\n * });\n * ```\n *\n * @param logger The winston logger instance to forward logs to. Must implement\n * the Logger interface with error, warn, info, http, verbose,\n * debug, and silly methods.\n * @param options Configuration options for the sink behavior.\n * @returns A sink function that can be used with LogTape's configure() function.\n * @since 1.0.0\n */\nexport function getWinstonSink(\n logger: Logger,\n options: WinstonSinkOptions = {},\n): Sink {\n const { levelsMap = DEFAULT_LEVELS_MAP, valueFormatter = inspect } = options;\n const categoryOptions = !options.category\n ? undefined\n : typeof options.category === \"object\"\n ? options.category\n : {};\n const category: Required<CategoryOptions> | undefined =\n categoryOptions == null ? undefined : {\n separator: categoryOptions.separator ?? \"·\",\n position: categoryOptions.position ?? \"start\",\n decorator: categoryOptions.decorator ?? \":\",\n };\n\n return (record: LogRecord) => {\n const level = levelsMap[record.level];\n let message = \"\";\n if (category?.position === \"start\" && record.category.length > 0) {\n const joinedCategory = record.category.join(category.separator);\n message += category.decorator === \"[]\"\n ? `[${joinedCategory}] `\n : category.decorator === \"()\"\n ? `(${joinedCategory}) `\n : category.decorator === \"<>\"\n ? `<${joinedCategory}> `\n : category.decorator === \"{}\"\n ? `{${joinedCategory}} `\n : category.decorator === \":\"\n ? `${joinedCategory}: `\n : category.decorator === \"-\"\n ? `${joinedCategory} - `\n : category.decorator === \"|\"\n ? `${joinedCategory} | `\n : category.decorator === \"/\"\n ? `${joinedCategory} / `\n : `${joinedCategory} `;\n }\n for (let i = 0; i < record.message.length; i += 2) {\n message += record.message[i];\n if (i + 1 < record.message.length) {\n message += valueFormatter(record.message[i + 1]);\n }\n }\n if (category?.position === \"end\" && record.category.length > 0) {\n const joinedCategory = record.category.join(category.separator);\n message += category.decorator === \"[]\"\n ? ` [${joinedCategory}]`\n : category.decorator === \"()\"\n ? ` (${joinedCategory})`\n : category.decorator === \"<>\"\n ? ` <${joinedCategory}>`\n : category.decorator === \"{}\"\n ? ` {${joinedCategory}}`\n : category.decorator === \":\"\n ? `: ${joinedCategory}`\n : category.decorator === \"-\"\n ? ` - ${joinedCategory}`\n : category.decorator === \"|\"\n ? ` | ${joinedCategory}`\n : category.decorator === \"/\"\n ? ` / ${joinedCategory}`\n : ` ${joinedCategory}`;\n }\n logger[level](message, record.properties);\n };\n}\n\n/**\n * Automatically configures LogTape to route all logs to a winston logger.\n *\n * This is a convenience function that automatically sets up LogTape to forward\n * all log records to a winston logger instance. By default, it uses winston's\n * default logger, but you can provide a custom logger as the first parameter.\n *\n * @param logger The winston logger instance to use.\n * @param options Configuration options for the winston sink behavior.\n *\n * @example Basic auto-configuration with default logger\n * ```typescript\n * import { install } from \"@logtape/adaptor-winston\";\n *\n * // Automatically route all LogTape logs to winston's default logger\n * install();\n *\n * // Now any LogTape-enabled library will log through winston\n * import { getLogger } from \"@logtape/logtape\";\n * const logger = getLogger(\"my-app\");\n * logger.info(\"This will be logged through winston\");\n * ```\n *\n * @example Auto-configuration with custom winston logger\n * ```typescript\n * import winston from \"winston\";\n * import { install } from \"@logtape/adaptor-winston\";\n *\n * const customLogger = winston.createLogger({\n * level: \"info\",\n * format: winston.format.combine(\n * winston.format.timestamp(),\n * winston.format.json()\n * ),\n * transports: [\n * new winston.transports.Console(),\n * new winston.transports.File({ filename: \"app.log\" })\n * ]\n * });\n *\n * // Install with custom logger\n * install(customLogger);\n * ```\n *\n * @example Auto-configuration with custom options\n * ```typescript\n * import { install } from \"@logtape/adaptor-winston\";\n *\n * install(undefined, {\n * category: {\n * position: \"start\",\n * decorator: \"[]\",\n * separator: \".\"\n * },\n * levelsMap: {\n * \"trace\": \"debug\" // Map LogTape trace to winston debug\n * }\n * });\n * ```\n *\n * @example Custom logger with custom options\n * ```typescript\n * import winston from \"winston\";\n * import { install } from \"@logtape/adaptor-winston\";\n *\n * const customLogger = winston.createLogger({\n * transports: [new winston.transports.Console()]\n * });\n *\n * install(customLogger, {\n * category: { position: \"start\", decorator: \"[]\" }\n * });\n * ```\n *\n * @since 1.0.0\n */\nexport function install(\n logger: Logger,\n options?: WinstonSinkOptions,\n): void;\n\n/**\n * Configures LogTape to route all logs to winston's default logger.\n *\n * @param options Optional configuration for the winston sink behavior.\n * @since 1.0.0\n */\nexport function install(\n options?: WinstonSinkOptions,\n): void;\n\nexport function install(\n loggerOrOptions?: Logger | WinstonSinkOptions,\n options: WinstonSinkOptions = {},\n): void {\n let logger: Logger;\n let sinkOptions: WinstonSinkOptions;\n\n // Handle overloaded parameters\n if (\n loggerOrOptions && (\"error\" in loggerOrOptions || \"info\" in loggerOrOptions)\n ) {\n // First parameter is a Logger\n logger = loggerOrOptions as Logger;\n sinkOptions = options;\n } else {\n // First parameter is WinstonSinkOptions or undefined\n logger = winston;\n sinkOptions = (loggerOrOptions as WinstonSinkOptions) || {};\n }\n\n configureSync({\n sinks: {\n winston: getWinstonSink(logger, sinkOptions),\n },\n loggers: [\n {\n category: [\"logtape\", \"meta\"],\n sinks: [\"winston\"],\n lowestLevel: \"warning\",\n },\n { category: [], sinks: [\"winston\"] },\n ],\n });\n}\n"],"mappings":";;;;;AAoMA,MAAMA,qBAA+D;CACnE,SAAS;CACT,SAAS;CACT,QAAQ;CACR,WAAW;CACX,SAAS;CACT,SAAS;AACV;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4DD,SAAgB,eACdC,QACAC,UAA8B,CAAE,GAC1B;CACN,MAAM,EAAE,YAAY,oBAAoB,iBAAiB,SAAS,GAAG;CACrE,MAAM,mBAAmB,QAAQ,2BAEtB,QAAQ,aAAa,WAC5B,QAAQ,WACR,CAAE;CACN,MAAMC,WACJ,mBAAmB,gBAAmB;EACpC,WAAW,gBAAgB,aAAa;EACxC,UAAU,gBAAgB,YAAY;EACtC,WAAW,gBAAgB,aA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AAIK;AAGJ,KACE,oBAAoB,WAAW,mBAAmB,UAAU,kBAC5D;AAEA,WAAS;AACT,gBAAc;CACf,OAAM;AAEL,WAAS;AACT,gBAAe,mBAA0C,CAAE;CAC5D;AAED,eAAc;EACZ,OAAO,EACL,SAAS,eAAe,QAAQ,YAAY,CAC7C;EACD,SAAS,CACP;GACE,UAAU,CAAC,WAAW,MAAO;GAC7B,OAAO,CAAC,SAAU;GAClB,aAAa;EACd,GACD;GAAE,UAAU,CAAE;GAAE,OAAO,CAAC,SAAU;EAAE,CACrC;CACF,EAAC;AACH"}
|
package/mod.ts
CHANGED
|
@@ -447,6 +447,11 @@ export function install(
|
|
|
447
447
|
winston: getWinstonSink(logger, sinkOptions),
|
|
448
448
|
},
|
|
449
449
|
loggers: [
|
|
450
|
+
{
|
|
451
|
+
category: ["logtape", "meta"],
|
|
452
|
+
sinks: ["winston"],
|
|
453
|
+
lowestLevel: "warning",
|
|
454
|
+
},
|
|
450
455
|
{ category: [], sinks: ["winston"] },
|
|
451
456
|
],
|
|
452
457
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@logtape/adaptor-winston",
|
|
3
|
-
"version": "1.0.0-dev.
|
|
3
|
+
"version": "1.0.0-dev.262+96c86667",
|
|
4
4
|
"description": "winston adapter for LogTape logging library",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"logging",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
],
|
|
58
58
|
"peerDependencies": {
|
|
59
59
|
"winston": "^3.17.0",
|
|
60
|
-
"@logtape/logtape": "1.0.0-dev.
|
|
60
|
+
"@logtape/logtape": "1.0.0-dev.262+96c86667"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
63
|
"@alinea/suite": "^0.6.3",
|