Skip to content

Latest commit

 

History

History
59 lines (45 loc) · 1.6 KB

README.md

File metadata and controls

59 lines (45 loc) · 1.6 KB

log

Build Status Coverage Status

A package for creating logs in S3

Installation

npm install @janiscommerce/log

API

  • add(log, bucketName)
    Parameters: log [Object], bucketName [String]
    Puts the recieved log into the specified S3 bucket.

  • on(event, callback)
    Parameters: event [String], callback [Function] Calls a callback when the specified event is emitted.

Errors

The errors are informed with a LogError.
This object has a code that can be useful for a correct error handling.
The codes are the following:

Code Description
1 Invalid log
2 Invalid bucket
3 S3 Error

In case of error while creating your log into S3, this package will emit an event called create-error, you can handle it using the on() method.

Usage

const Log = require('@janiscommerce/log');

Log.add({
	type: 1,
	entity: 'api',
	entity_id: 'product',
	message: '[GET] Request from 0.0.0.0 of custom_data'
	// ...
}, 'my-bucket');

Log.on('create-error', (log, err) => {
	console.error(`An error occurred while creating the log ${err.message}`);
});

Notes

In order to connect into S3, this package requires the aws volume in the docker-compose.yml.

volumes:
  ~/.aws:/root/.aws