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

@5app/logger

Package Overview
Dependencies
Maintainers
5
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@5app/logger

Logger used in 5app microservices

  • 1.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
560
increased by4.28%
Maintainers
5
Weekly downloads
 
Created
Source

logger

Simple console logger that outputs json in prod and pretty messages on dev

Usage

npm install --save @5app/logger

Then, generate a logger in your app and use it to log messages.

const {logger} = require('@5app/logger');

logger.info('An email was sent', {
  email: 'customer@5app.com',
  template: 'template1',
});

logger.error(new Error('Unknown playlist 123'));

Alternatively, you can create a new instance of logger where you can specify the metadata, logging level, and whether you want simple logs or not:

const {getLogger} = require('@5app/logger');

const logger = getLogger({
  simple: process.env.NODE_ENV === 'development',
  metadata: {
    tag: process.env.TAG, // release tag, e.g. docker container tag
  },
});

logger.info('An email was sent', {
  email: 'customer@5app.com',
  template: 'template1',
});

logger.error(new Error('Unknown playlist 123'));

Options

The logger generator accepts the following options:

simple

This boolean value specifies whether we should log pretty dev-friendly messages instead of JSON or not. By default, simple will be false.

Example:

const {getLogger} = require('@5app/logger');

// This logger will log dev-friendly messages
const logger = getLogger({
  simple: true,
});

The default logger uses the environment variable LOGS_FORMAT to determine if the logs are going to be generated in json (json) or simple console logs (any other value other than json).

metadata

Metadata is an object containing service metadata like the release tag or the A/B testing experiment we are running. This object will be added to each log entry when using the JSON mode.

Example:

const {getLogger} = require('@5app/logger');

// This logger will add details about the current release and A/B experiment to every log line
const logger = getLogger({
  metadata: {
    release: '1.2.3',
    experiment: 12345,
  },
});

level

You can specify a minimum logging level using the level parameter or using the LOGS_LEVEL environment variable. By default, the logging level will be debug (npm).

Example:

const {getLogger} = require('@5app/logger');

// This logger will add details about the current release and A/B experiment to every log line
const logger = getLogger({
  level: 'warn',
});

logger.info('this message will not be logged');
logger.warn('you will see this message');

Keywords

FAQs

Package last updated on 12 Sep 2019

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