Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bunyan

Package Overview
Dependencies
Maintainers
1
Versions
112
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bunyan

a JSON logging library for node.js services

  • 1.8.15
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

What is bunyan?

The bunyan npm package is a simple and fast JSON logging library for node.js services. It provides a high-level abstraction around the process of logging and allows developers to create structured logs in JSON format. These logs are easy to read for humans and easy to parse for machines, making bunyan suitable for production debugging and monitoring.

What are bunyan's main functionalities?

Creating a Logger

This feature allows you to create a logger instance with a specified name. You can then use this instance to log messages at different levels, such as info, error, warn, etc.

const bunyan = require('bunyan');
const log = bunyan.createLogger({ name: 'myapp' });
log.info('Hello Bunyan');

Logging at Different Levels

Bunyan provides methods to log messages at various levels, which helps in filtering and categorizing logs based on their severity.

log.trace('This is a trace message');
log.debug('This is a debug message');
log.info('This is an info message');
log.warn('This is a warning message');
log.error('This is an error message');
log.fatal('This is a fatal message');

Adding Metadata to Logs

You can add additional metadata to your logs by passing an object as the first argument to any of the logging methods. This is useful for adding context to your logs.

log.info({user: 'john_doe'}, 'User logged in');

Stream Configuration

Bunyan allows you to configure multiple streams for your logs, directing them to different outputs, such as stdout or a file, and at different log levels.

const log = bunyan.createLogger({
  name: 'myapp',
  streams: [
    {
      level: 'info',
      stream: process.stdout
    },
    {
      level: 'error',
      path: '/var/log/myapp-error.log'
    }
  ]
});

Child Loggers

You can create child loggers from an existing logger instance. Child loggers inherit the streams and log level of the parent but can add additional metadata, which is useful for logging within specific components or modules.

const childLog = log.child({ component: 'mycomponent' });
childLog.info('Component initialized');

Other packages similar to bunyan

Keywords

FAQs

Package last updated on 08 Jan 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc