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

@janiscommerce/log

Package Overview
Dependencies
Maintainers
1
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@janiscommerce/log

A package for creating logs in S3

  • 1.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
587
increased by16.7%
Maintainers
1
Weekly downloads
 
Created
Source

log

Build Status Coverage Status

A package for creating logs in S3

Installation

npm install @janiscommerce/log

Configuration

ENV variables

JANIS_SERVICE_NAME (required): The name of the service that will create the log.

API

add(bucketName, log)

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

Log structure

The log [Object] parameter have the following structure:

  • type [String|Number] (required): The log type
  • entity [String] (required): The name of the entity that is creating the log
  • entity_id [String] (optional): The ID of the entity that is creating the log
  • message [String] (optional): A general message about the log
  • log [Object] (optional): This property is a JSON that includes all the technical data about your log.
  • date_created [unix_timestamp] (optional): The date created of the log. Default will be auto-generated.
  • id [String] (optional): The ID of the log in UUID V4 format. Default will be auto-generated.

Log example

{
  type: 'new',
  entity: 'api',
  entity_id: 'log',
  service: 'trace',
  message: '[GET] Request from 12.345.67.89 to /log',
  date_created: 1559103066,
  log: {
    verb: 'GET',
    headers: {
      'x-forwarded-for': '12.345.67.89',
      'x-forwarded-proto: 'https',
      'x-forwarded-port: '443',
    },
    responseHttpCode: 200
  },
  id: '0acefd5e-cb90-4531-b27a-e4d236f07539'
}

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:

CodeDescription
1Invalid log
2Invalid bucket
3S3 Error
4Unknown service name

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('my-bucket', {
	type: 1,
	entity: 'api',
	entity_id: 'product',
	message: '[GET] Request from 0.0.0.0 of custom_data'
	// ...
});

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

FAQs

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