Skip to content

meteorid-labs/truck-logger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

18 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

@meteor-labs/truck-logger
Truck Logger

A minimal Express Logger built with Winston.

Installation โ€ข How to use

Installation

  1. Install package
    # using npm
    npm i @meteor-labs/truck-logger
    # using yarn
    yarn add @meteor-labs/truck-logger
  2. Add your MongoDB access to your .env
     TRUCK_REQUEST_KEY= // requestId. default: truckNo
     TRUCK_DB_HOST=
     TRUCK_DB_PORT=
     TRUCK_DB_USER=
     TRUCK_DB_PASSWORD=

How To Use

To use truck-logger add truckExpress to your API Route. Here is an example:

const { truckExpress } = require('@meteor-labs/truck-logger');

app.get('/truck/number/1', truckExpress('truck_1_collection'), ...);

// or

router.get('/truck/number/1', truckExpress('truck_1_collection'), ...);

and.. That`s it!! ๐Ÿฆ€

As default truckExpress will be generated request result for you, which is log console & log data on MongoDB along with default meta info inside. Like this:

ss_1

ss_2

Oh.. If you want to create new log with same truckNo (requestId). You can do this inside your controller:

const { truck } = require('@meteor-labs/truck-logger');

const truck1Controller = () => {
  ...

  truck().info('The truck is still on its way..')

  truck().warn('Almost there..')

  truck().error('Oops..')
  
  ...
};

Screenshot 2022-12-30 at 16 04 08

Credits

This package uses the following open source packages:

Support

Buy Me A Coffee