← All @molecule/* packages · App templates
@molecule/api-logger-winstonProvider bond · logger · API (Node) · v1.0.1 · Apache-2.0
Winston logger provider for molecule.dev.
npm install @molecule/api-logger-winstonnpm · Source on GitHub · Implements @molecule/api-logger
@molecule/api-logger-winston is a provider bond on the API (Node) side: it implements the logger core interface (@molecule/api-logger) with a concrete vendor or library behind it.
Your code calls the core; you wire this provider once at startup. Swapping vendors later is one line in that wiring, not a rewrite.
import { logger, setLogger } from '@molecule/api-logger'
import { createLogger, provider } from '@molecule/api-logger-winston'
// Default: colorized console output
setLogger(provider)
logger.info('Server started on port', 3000)
logger.error('Database connection failed', error) // message + full stack
// Custom instance: JSON to a file — level omitted, so this instance defers
// to the core's LOG_LEVEL/setLevel() gate
setLogger(
createLogger({
format: 'json',
transports: [{ type: 'file', options: { filename: 'app.log' } }],
}),
)Works with: @molecule/api-logger
Auto-generated, AI-first package reference for the molecule.dev ecosystem. It is written to be read by coding agents as much as by people, and is generated from this package's source — edit
src/index.tsJSDoc, not this file.
Winston logger provider for molecule.dev.
Provides a full-featured logger implementation using winston.
import { logger, setLogger } from '@molecule/api-logger'
import { createLogger, provider } from '@molecule/api-logger-winston'
// Default: colorized console output
setLogger(provider)
logger.info('Server started on port', 3000)
logger.error('Database connection failed', error) // message + full stack
// Custom instance: JSON to a file — level omitted, so this instance defers
// to the core's LOG_LEVEL/setLevel() gate
setLogger(
createLogger({
format: 'json',
transports: [{ type: 'file', options: { filename: 'app.log' } }],
}),
)
provider
npm install @molecule/api-logger-winston @molecule/api-logger winston
LoggerLogger interface that all implementations must satisfy.
interface Logger {
trace(...args: unknown[]): void
debug(...args: unknown[]): void
info(...args: unknown[]): void
warn(...args: unknown[]): void
error(...args: unknown[]): void
}
WinstonLoggerOptionsOptions for creating a winston logger.
interface WinstonLoggerOptions {
/**
* Minimum level for the winston instance. Defaults to `'trace'`
* (pass-through, via winston's `'silly'` level) — minimum-level filtering
* is meant to happen once, in `@molecule/api-logger`'s gate (`LOG_LEVEL` /
* `setLevel()`). Pass an explicit `level` only to add a second, stricter
* gate on this instance specifically. `'silent'` is implemented via
* winston's `silent: true` flag (winston has no built-in `'silent'` level).
*/
level?: LogLevel
/** Output format. Defaults to `'json'` (timestamps + error stacks); `'console'` is colorized. */
format?: 'json' | 'console'
/** Transports to attach. Defaults to a single console transport. */
transports?: WinstonTransportConfig[]
}
WinstonTransportConfigConfiguration for a winston transport.
stream expects a writable stream in options.stream — useful for tests
and in-process sinks. Unknown types fall back to a console transport.
interface WinstonTransportConfig {
type: 'console' | 'file' | 'http' | 'stream' | string
/** Per-transport level override. Omitted = inherit the parent logger's level (NOT pass-through). */
level?: LogLevel
options?: Record<string, unknown>
}
LogLevelLog levels supported by the logger.
type LogLevel = 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'silent'
createLogger(options)Creates a winston-based logger that implements the Logger interface.
Supports console, file, HTTP, and stream transports.
function createLogger(options?: WinstonLoggerOptions): Logger
options — Winston configuration (log level, format, transports).Returns: A Logger backed by winston.
formatWinston format utilities for convenience.
const format: typeof winston.format
providerThe default winston logger with console format.
Level filtering is delegated to @molecule/api-logger's gate (LOG_LEVEL /
setLevel(), default 'info') — the underlying instance passes everything
through so the core's single gate governs; a second gate here would make the
core's setLevel('debug') silently no-op.
const provider: Logger
transportsWinston transports for convenience.
const transports: winston.transports.Transports
winstonImplements @molecule/api-logger interface.
Setup function to register this provider with the core interface:
import { setLogger } from '@molecule/api-logger'
import { provider } from '@molecule/api-logger-winston'
export function setupLoggerWinston(): void {
setLogger(provider)
}
Peer dependencies:
@molecule/api-logger ^1.0.1@molecule/api-logger
winston
Console-style variadic calls are bridged onto winston's
(message, meta) shape: logger.info('msg', contextObj) merges
contextObj into the record, and an Error (alone or after a message)
keeps its stack. Naively stringifying args would print [object Object]
and drop stacks.
Both the default provider AND createLogger() (level omitted) pass
every level through to winston — minimum-level filtering happens once, in
@molecule/api-logger (LOG_LEVEL / setLevel(), default 'info').
Passing an explicit level to createLogger() adds a SECOND, bond-side
gate below the core's; a stricter level there makes the core's
setLevel('debug') appear to do nothing — only do this if you actually
want a second, independent filter on this specific instance.
level: 'silent' is implemented via winston's silent: true flag (there
is no built-in winston 'silent' level) — it drops output unconditionally,
regardless of the configured level.
Transport types: console, file, http, and stream
(options.stream = any writable — handy for tests and in-process sinks).
A transport's own level follows the same rules as createLogger's
top-level level; omitted, it inherits the parent instance's level
instead of defaulting to anything.