package
Log errors with Winston
npm install winston-error-formatGitHub-flavored package documentation.
Across all versions.
Download trend unavailable.
Runtime metadata.
Tagged topics.
Log errors with Winston.
This provides with two Winston formats:
Unlike Winston's default error format:
name is loggedcause
and aggregate
errorsUsing the full format.
import { createLogger, format, transports } from 'winston'
import { fullFormat } from 'winston-error-format'
const logger = createLogger({
format: format.combine(fullFormat(), format.json()),
transports: [new transports.Http(httpOptions)],
})
const error = new ExampleError('Could not read file.')
error.filePath = '/...'
logger.error(error)
// Sent via HTTP:
// {
// level: 'error',
// name: 'ExampleError',
// message: 'Could not read file.',
// stack: `ExampleError: Could not read file.
// at ...`,
Using the short format.
import { createLogger, format, transports } from 'winston'
import { shortFormat } from 'winston-error-format'
const logger = createLogger({
format: format.combine(shortFormat(), format.cli()),
transports: [new transports.Console()],
})
const error = new ExampleError('Could not read file.')
logger.error(error)
// Printed on the console:
// error: ExampleError: Could not read file.
// at ...npm install winston-error-formatThis package requires installing Winston separately.
npm install winstonThis package works in Node.js >=18.18.0.
This is an ES module. It must be loaded using
an import or import() statement,
not require(). If TypeScript is used, it must be configured to
output ES modules,
not CommonJS.
options: Options
Return value: Format
Returns a logger
format
to combine with
format.json() or
format.prettyPrint(). This
logs all error properties, making it useful with
transports like
.
Errors should be logged using
logger.*(error).
options: Options
Return value: Format
Returns a logger
format
to combine with
format.simple() or
format.cli(). This logs only the
error name, message and stack, making it useful with
transports like the
.
Errors should be logged using
logger.*(error).
Type: object | ((Error) => object)
The options object can be error-specific by passing a function returning it instead.
Type: boolean
Default: true
Whether to log the stack trace.
Type: string
Override the log level.
Type: (Error) => Error
Maps the error before logging it.
winston: A logger for just about
everythingmodern-errors: Handle errors in
a simple, stable, consistent waymodern-errors-winston:
Log errors with Winstonerror-custom-class: Create
one error classFor any question, don't hesitate to submit an issue on GitHub.
Everyone is welcome regardless of personal background. We enforce a Code of conduct in order to promote a positive and inclusive environment.
This project was made with ❤️. The simplest way to give back is by starring and sharing it online.
If the documentation is unclear or has a typo, please click on the page's Edit
button (pencil icon) and suggest a correction.
If you would like to help us fix a bug or add a new feature, please check our guidelines. Pull requests are welcome!
error-class-utilserror-serializer: Convert
errors to/from plain objectsnormalize-exception:
Normalize exceptions/errorsis-error-instance: Check if
a value is an Error instancemerge-error-cause: Merge an
error with its causeset-error-class: Properly
update an error's classset-error-message: Properly
update an error's messagewrap-error-message:
Properly wrap an error's messageset-error-props: Properly
update an error's propertiesset-error-stack: Properly
update an error's stackerror-cause-polyfill:
Polyfill error.causehandle-cli-error: 💣 Error
handler for CLI applications 💥safe-json-value: ⛑️ JSON
serialization should never faillog-process-errors: Show
some ❤ to Node.js process errorserror-http-response:
Create HTTP error responsesEstimated unpacked size across 14 packages.
500.1 kB
Includes dependencies.
7 direct dependencies.
^2.7.0
2.7.0
^1.4.1
1.4.1
^4.1.0
4.1.0
^3.0.1
3.0.1
^8.0.1
8.0.2
^3.0.1
3.0.1
^4.0.1
4.0.1