npm / tslog
tslog
What changed in tslog 4 to 5, from its official release notes, upgrade guides and advisories. Sources checked 2026-10-22.
20 breaking3 security50 new APIs and options2 behavior and defaults1 tooling9 fixes and other
See which of these apply to your code, ranked, in your agent:
npx @unstale/cli inittslog 573 changes
Breaking changes 20
Node 20 support is dropped.
In browser CSS output, foreground whiteBright no longer contributes a color declaration, keeping text readable on light and dark consoles.
The nested JSON shape containing the message under key 0 has been removed.
The CommonJS build and require("tslog") have been removed.
Node JSON output no longer uses console.log; code intercepting it must spy on process.stdout.write or use a transport.
tslog is now ESM-only; CommonJS consumers must change how they load the package.
Removed in favor of the stack group and environment-aware defaults.
Registers middleware that can mutate each log context or drop a log entirely.
The loggerEnvironment/createLoggerEnvironment singleton is removed; entry points export their own environment factories.
Runtime metadata moves under _logMeta and carries a v: 5 schema marker.
Masking settings are grouped under mask, replacing flat maskValues* keys.
Masking is off by default because mask.keys starts empty; enable it explicitly.
Metadata settings are grouped under meta instead of the removed metaProperty setting.
The minimum supported Node.js version is 20.
The overwrite hooks have been removed; use middleware and per-transport format instead.
Related settings now live under the pretty group instead of flat prettyLog* keys.
Flat settings keys including prettyLogTemplate have been removed in favor of grouped settings.
In toOtelRecord, resource attributes now take precedence over colliding per-record fields.
Stack settings are grouped under stack; this group also supersedes hideLogPositionForProduction.
When omitted, output defaults to pretty in server, CI, browser, and React Native; coloring adapts to the environment.
Security 2
Masking now applies inside logged errors, including the whole stack header of multi-line errors; masked DOMExceptions retain their name and message.
LiteLogger accepts a name label for named sub-loggers. Labels escape % characters so they cannot act as console format specifiers; on named lite loggers, printf-style specifiers in messages print literally.
New APIs and options 44
Register custom tokens for pretty.template, style them through pretty.styles, and inherit the placeholder map in sub-loggers. Only referenced tokens are evaluated; throwing callbacks render empty without dropping the log.
LiteLogger gains child() for creating nested named sub-loggers that inherit minLevel and the sink unless overridden.
LiteLogger gains getSubLogger() for creating nested named sub-loggers that inherit minLevel and the sink unless overridden.
Controls how nested sub-logger names are joined; the default separator is :.
Adds an API for adding a log level.
Attaches asynchronous transports and returns a detach function; transports can declare minLevel and format.
Adds child() as an alias of getSubLogger().
Adds an injectable top-level clock inherited by sub-loggers.
Adds configurable custom log levels, used with log(levelId, levelName, ...args).
Adds a configuration helper.
Forces styled pretty output.
Adds an API for retrieving logger context.
Adds a custom body encoder for endpoints whose payload is neither NDJSON nor a JSON array.
Level methods accept fields-first calls as well as message-first calls; object fields spread into JSON output.
Checks whether a log level is enabled, allowing callers to skip expensive payload construction.
Related JSON settings are grouped under json; all JSON keys are configurable via this group.
Controls the top-level timestamp representation using iso, epoch, false, or a function.
Flushes asynchronous transports and buffered output.
Adds an environment-based Logger factory.
Returns the logger when a condition is truthy and a no-op stand-in otherwise, enabling fluent conditional logging.
Selects how masked values are censored: remove, hash, a string, or a function.
Masks values selected by JSONPath-ish patterns such as user.password or *.token.
Adds regular-expression-based masking.
Strips colors without switching the output format.
Can be paired with native pretty objects for native warn/error stack groups.
Passes non-Error arguments to the console by reference for interactive browser DevTools rendering; enabled by default in real browsers.
Propagates context fields through AsyncLocalStorage into _logMeta when meta.attachContext is enabled.
Supports asynchronous disposal of logger resources, including await using.
Adds APIs to wrap, restore, and check whether the console is wrapped.
Adds minimal console wrappers that preserve native line numbers.
Adds OpenTelemetry formatters, record conversion, severity helpers, and trace-context utilities.
Adds GenAI presets and helpers that emit OTel gen_ai.* fields.
Adds pino-compatible formatting, transport, and level conversion helpers.
Adds box and tree pretty-printing helpers.
Exports standard serializers and a serialize(map) middleware helper.
Adds a smaller structured-JSON build without masking, pretty output, or stack capture; unsupported mask settings and pretty type throw.
Adds createTestLogger, mockLogger, and normalizeMeta for deterministic test output.
Adds rate-limit middleware.
Adds a non-blocking file transport with flush and dispose support.
Adds a batched HTTP transport.
Adds a ring-buffer transport with dump and clear methods.
Adds a Node-only worker transport that performs sink I/O off-thread.
Selects structured JSON output when set to json.
Adds a configuration error thrown when strictConfig is enabled.
Behavior and default changes 2
Misspelled style keys now warn in development with a did-you-mean, or throw TslogConfigError with UNKNOWN_PRETTY_STYLE under strictConfig.
React Native is detected, reported in _logMeta.runtime, and uses pretty output by default with Hermes/JSC stack parsing.
Tooling 1
Adds the tslog executable, an NDJSON pretty-printer for stdin.
Fixes and other changes 4
ANSI colors are kept out of pretty transport lines.
In browser CSS output, foreground white no longer contributes a color declaration, keeping text readable on light and dark consoles.
Fixes default browser console error styling, stack parsing, and log positions.
Source-mapped error positions work out of the box with modern bundler output, including Turbopack/Next.js dev, Rollup, and Webpack.
tslog 412 changes
Security 1
Hardens transport and masking.
New APIs and options 6
Custom addMeta handlers can optionally receive default meta.
Adds configuration validation as a runtime feature.
Adds the fileNameWithLine style.
Adds named log levels and exposes DefaultLogLevels for default log levels.
Adds prettyLogLevelMethod for routing log levels.
Adds unified stack detection as a runtime feature.
Fixes and other changes 5
Fixes bigint handling.
Fixes handling of invalid dates.
Fixes local timezone handling.
Fixes meta types.
Fixes worker styling.