New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@epsor/logger

Package Overview
Dependencies
Maintainers
24
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@epsor/logger

Epsor logging superset over Winston for console and elasticsearch

  • 2.0.0
  • unpublished
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
24
Weekly downloads
 
Created
Source

@epsor/logger

This is the custom logger package for Epsor. Use it as soon as you need some logs.

  • @epsor/logger

Usage

@epsor/logger assumes that a few environment variables are set:

  • ELASTICSEARCH_URL, ELASTICSEARCH_USER and ELASTICSEARCH_PASSWORD to identify against Elasticsearch node,
  • SERVICE_NAME to identify which part of the app sent the log
  • ENVIRONMENT
  • SENTRY_DSN the Sentry's data source name to push error logs to Sentry
import logger from '@epsor/logger';

logger.info('Hello World!');

View logs

Logs are pushed:

  • in your console,
  • in your Elasticsearch instance (log levels info or less only, see log levels for more information).
  • in Sentry

Log levels

Logger uses the npm logging levels, prioritized from 0 to 5 :

{
  error: 0,
  warn: 1,
  info: 2,
  verbose: 3,
  debug: 4,
  silly: 5
}

All log levels are logged to your console, but only log levels info or less are pushed to Elasticsearch, and only error logs are pushed to Sentry. It allows developer to add logs for local debug purpose only.

Guidelines

Log format

For optimal readability of logs:

  • Use a human-readable log message
  • Add useful metadata (user, error stack...)

To add metadata in your logs, use an object as the second argument:

logger.info(
  'Thats a nice message!',
  {
    user: {
      email: 'julien.murgey@epsor.fr',
      firstname: 'Julien'
      lastname: 'MURGEY'
      id: 48,
    },
  },
)

Tags

To be able to easily find in the codebase where log has been done, add tags in metadata that will be searchable in Kibana.

Example of good tags: transactions, instructions, profile selection, deposit, arbitration...

try {
  //do something
} catch (e) {
  logger.error(
    'Error happened!'
    {
      user: {
        email: 'julien.murgey@epsor.fr',
        firstname: 'Julien'
        lastname: 'MURGEY'
        id: 48,
      },
      tags: ['import', 'contribution'],
      errorStack: e.stack,
    }
  );
}

FAQs

Package last updated on 08 Nov 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