Registry / devops / winston-json-formatter

winston-json-formatter

JSON →
library0.10.0jsnpmunverified

A JSON and console formatter for winston@3, version 0.10.0. Enables structured logging with configurable output formats (JSON or console) and automatic hostname detection. Supports direct error object logging, custom metadata, and environment-based format switching via NODE_ENV. Released under ISC license, maintained on GitHub by amida-tech. Differentiates from other formatters by offering a simple configuration interface inspired by winston's format system, though it uses the legacy `logger.format` assignment rather than the modern `format` pipeline.

npm install winston-json-formatter
INSTALL
IMPORT
SIG · WINSTON-JSON-FORMA
W
winston-json-formatter
devopsjavascriptv0.10.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

configuredFormatter
✓ import { configuredFormatter } from 'winston-json-formatter'
✗ const configuredFormatter = require('winston-json-formatter')
Package is ESM-only since v0.10.0; CommonJS require will fail.
default
✓ import configuredFormatter from 'winston-json-formatter'
✗ import { configuredFormatter } from 'winston-json-formatter'
Only a default export is provided; named import will result in undefined.
configuredFormatter (TypeScript)
✓ import configuredFormatter from 'winston-json-formatter'
✗ import { configuredFormatter } from 'winston-json-formatter'
TypeScript users must use default import; types are included.

Sets up a Winston logger with JSON formatting using winston-json-formatter, demonstrating basic logging and error object handling.

import winston from 'winston'; import configuredFormatter from 'winston-json-formatter'; const logger = winston.createLogger({ level: 'silly', transports: [new winston.transports.Console()] }); const options = { service: 'test-service', logger: 'Winston-JSON-Formatter', version: '1.0.0', typeFormat: 'json' }; logger.format = configuredFormatter(options); logger.info('Hello, world!'); logger.error(new Error('Something broke'));
Debug
Known issues
breakingPackage migrated to ESM-only in v0.10.0; CommonJS require() will fail.
fix
Use import syntax or dynamic import().
affects: >=0.10.0
gotchaThe formatter is assigned to logger.format, overriding the default format. Do not use winston.format.combine() with this package.
fix
Set logger.format = configuredFormatter(options) directly.
affects: *
gotchaNODE_ENV=dev or NODE_ENV=development forces console format regardless of options.typeFormat.
fix
Set NODE_ENV to production or another value to use JSON format.
affects: *
deprecatedThe 'node_env' option is misnamed (lowercase with underscore) compared to standard NODE_ENV.
fix
Use the upper-case environment variable NODE_ENV instead.
affects: *
Errors
Common errors & fixes
Cannot find module 'winston-json-formatter'
Package not installed or wrong import syntax in CommonJS.
fix
npm install winston-json-formatter && use import configuredFormatter from 'winston-json-formatter'.
TypeError: configuredFormatter is not a function
Using named import { configuredFormatter } instead of default import.
fix
Change to import configuredFormatter from 'winston-json-formatter'.
TypeError: Cannot assign to read only property 'format' of object '#<Logger>'
Logger format is frozen in winston@3; must assign during creation.
fix
Set logger.format = configuredFormatter(options) before any logging calls.
Upgrade
Version history
0.10.0latest on npm
Audit
Dependencies
winstonrequiredpeer dependency for logger and transports
Agent activity
7 hits · last 30 days
node
6
Resources
winston-json-formatter — npm install winston-json-formatter · libregistry