@first-lego-league/ms-logger
v2.0.2
Published
Logger for FIRST Lego League System Modules
Downloads
6
Keywords
Readme
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:
- 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.
- 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!