2.0.0 • Published 3 years ago

@epsor/logger v2.0.0

Weekly downloads
924
License
ISC
Repository
github
Last release
3 years ago

@epsor/logger

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

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,
    }
  );
}
2.0.0

3 years ago

1.2.0

3 years ago

2.0.0-dev

4 years ago

1.1.13

4 years ago

1.1.12

4 years ago

1.1.11

4 years ago

1.1.10

4 years ago

1.1.8

4 years ago

1.1.7

4 years ago

1.1.6

4 years ago

1.1.5

4 years ago

1.1.4

4 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.0

5 years ago