winston-humanize-console-transport
TypeScript icon, indicating that this package has built-in type declarations

1.3.1 • Public • Published

winston-humanize-console-transport

Print logs to the console in a human-readable format.

Installation

yarn add winston-humanize-console-transport

or

npm i -S winston-humanize-console-transport

Usage

import { createLogger, format } from 'winston'
import os from 'os'
import ConsoleTransport from 'winston-humanize-console-transport'

const { combine, timestamp } = format

const logger = createLogger({
  level: 'debug',
  defaultMeta: { pid: process.pid, host: os.hostname() },
  format: combine(timestamp()),
  transports: [new ConsoleTransport()],
})

Example

logger.debug('this is a debug message')
logger.info('this is an information', { a: 1, b: '2' })
logger.warn('this is a warning')
logger.error('this is an error', { stack: new Error('ttt') })

humanize

with humanize

simple

without humanize

Feature

  • Highlight log level with color.
  • Inspect metadata with type highlight.
  • Extract key information.
  • Hide non-essential metadata.
  • Print error stack independently.

Detail

We use following keys in metadata to highlight:

  • timestamp (you can combine timestamp on format)
  • module (to highlight module name)
  • traceId (to highlight trace id)
  • stack (to print error stack independently)
  • pid (to highlight process id)

License

MIT Licensed

Readme

Keywords

none

Package Sidebar

Install

npm i winston-humanize-console-transport

Weekly Downloads

28

Version

1.3.1

License

MIT

Unpacked Size

17 kB

Total Files

15

Last publish

Collaborators

  • cnwangjie