@first-lego-league/ms-logger

2.0.2 • Public • Published

npm codecov Build status GitHub

David Dependency Status David Dev Dependency Status David Peer Dependencies Status

FIRST Lego League Logger

A simple logger which works according to the FIRST LEGO League TMS Module Standard.

Usage

There are two ways to use the module: creating the logger directly ot using the middelware.

Create the logger directly

// import the logger
const { Logger } = require('@first-lego-league/ms-logger')

// Create a new instance
const logger = new Logger()

// Use the logger with the direct log method
// Passing to it the level and message
logger.log(logger.LOG_LEVELS.DEBUG, 'some message')
// Or use the level method directly
logger.debug('some message')

Available levels are: DEBUG, INFO, WARN, ERROR, FATAL

When you try to write a log, the logger only logs it if the message's level is higher then the log's logLevel. You can access the logLevel proeperty like this:

const { Logger } = require('@first-lego-league/ms-logger')

const logger = new Logger()
logger.logLevel = logger.LOG_LEVELS.WARN
console.log(logger.logLevel) // 2

Use the node middleware

const { loggerMiddleware } = require('@first-lego-league/ms-logger')
const app = require('express')()

app.use(loggerMiddleware)

This adds a double functionality:

  1. Each HTTP request to pass through this middleware will be logged, together with its method, URL, the time it took, its issuer and its status code.
  2. You can now request from the server to log using HTTP POST to the /log/:level endpoint: POST http://server/log/debug message="some message". The server responds with a 201 on success and a 500 on failure.

Contribution

To contribute to this repository, simply create a PR and set one of the Code Owners to be a reviewer. Please notice the linting and UT, because they block merge. Keep the package lightweight and easy to use. Thank you for contributing!

Readme

Keywords

none

Package Sidebar

Install

npm i @first-lego-league/ms-logger

Weekly Downloads

0

Version

2.0.2

License

GPL-3.0

Unpacked Size

44.5 kB

Total Files

9

Last publish

Collaborators

  • alanggreen
  • idanstark42
  • roy999
  • taltaub22
  • yosikarl