Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

@benchmate/logger

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@benchmate/logger

📃 logging library with support for structured logs (for cloud services) and local logging with colors

latest
Source
npmnpm
Version
1.1.0
Version published
Maintainers
1
Created
Source

:page_with_curl: @benchmate/logger

logging library with support for structured logs (for cloud services) and local logging with colors

Installation

First install the library:

yarn add @benchmate/logger

Usage

ES6 imports

Create a new log.js file, as follows:

import createLogger from '@benchmate/logger'

const makeLogger = service => createLogger('APPNAME', service)

export default makeLogger

Finally, use the logger:

import makeLogger from './log'
const { debug, info, warn, error, crit, exception } = makeLogger('SERVICENAME')

debug('Debug or trace information.')
info('Routine information, such as ongoing status or performance.')
warn('Warning events might cause problems.')
error('Error events are likely to cause problems.')
exception(new Error('something went wrong!'))
crit('Critical events cause more severe problems or outages.')
exception(new Error('fatal error'), 'crit')

node.js

Create a new log.js file, as follows:

const createLogger = require('@benchmate/logger')

module.exports = service => createLogger('APPNAME', service)

Finally, use the logger:

const { debug, info, warn, error, crit, exception } = require('./log')('SERVICENAME')

debug('Debug or trace information.')
info('Routine information, such as ongoing status or performance.')
warn('Warning events might cause problems.')
error('Error events are likely to cause problems.')
exception(new Error('something went wrong!'))
crit('Critical events cause more severe problems or outages.')
exception(new Error('fatal error'), 'crit')

Log levels

We use a subset of the official syslog log levels:

  • crit: Critical events cause more severe problems or outages.
  • error: Error events are likely to cause problems.
  • warn: Warning events might cause problems.
  • info: Routine information, such as ongoing status or performance.
  • debug: Debug or trace information.

Configuration

The logging library is configured using the following environment variables:

  • LOG_LEVEL (default: info) - everything higher than this level is logged
  • LOG_DISABLE_JSON (default: false) - disable structured JSON logs in production
  • NODE_ENV (default: development) - set to production to enable structured JSON logs or simpler logs (without colors)

Demo

Run yarn demo to see a demo of the logger:

yarn demo output

FAQs

Package last updated on 18 Jul 2020

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