0.1.1 • Published 2 years ago

pino-systemd-prefix-transport v0.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

pino-systemd-prefix-transport

pino-systemd-prefix-transport is a transport for the pino logger. pino-systemd-prefix-transport receives pino logs and adds a 3-character prefix '<' N '>' to the log, where N is a digit from 0 to 7 indicating severity of the log line.By default, Systemd will interpret the prefix as the log level, omit it, and log the rest of the string at the specified level.

This package might be useful if you run your node application as a Systemd service (for example, using the AWS Elastic Beanstalk cloud service), and you want to control the log level being sent to Syslog.

Reference: systemd.exec(5), sd-daemon(3)

Example

Given the log:

{"level":30,"time":1664851979134,"pid":20379,"hostname":"MacBook-Pro-3","msg":"hello world!"}

pino-systemd-prefix-transport will write out:

<6>{"level":30,"time":1664851979134,"pid":20379,"hostname":"MacBook-Pro-3","msg":"hello world!"}

Usage

const pino = require('pino')
const transport = pino.transport({
  target: 'pino-systemd-prefix-transport',
  level: 'info',
  options: {
    enablePipelining: false, // optional (default: true)
    destination: 1, // optional (default: stdout)
  }
})
pino(transport)

There are two configurable properties:

  • enablePipelining: set to false to disable the pino transport pipeline.
  • destination: an integer which is used to specify the destination of the log messages. 1 is stdout, 2 is stderr and others numbers must be a file descriptor. This option is used only when the pipelining is disabled.

Pipelining

This feature is enabled by default and let you to submit the output to another destination at your choice, such as a socket using the pino-socket module:

const transport = pino.transport({
  pipeline: [
    {
      target: 'pino-systemd-prefix-transport',
      level: 'info',
      options: {
        ... // other options
      }
    },
    {
      target: 'pino-socket',
      options: {
        mode: 'tcp',
        address: '127.0.0.1',
        port: 8001
      }
    }
  ]
})
pino(transport)

Note

pino legacy transport is not supported.

License

MIT