Skip to content

FirstLegoLeague/ms-logger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

npm codecov Build status GitHub

David Dependency Status David Dev Dependency Status David Peer Dependencies Status

FIRST Lego League Logger

A logger package, working according to the FIRST LEGO League TMS Module Standard logging section.

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!

About

Logger for FIRST Lego League System Moduels

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •