0.1.2 • Published 2 years ago

@dojot/dojot-module-logger v0.1.2

Weekly downloads
33
License
Apache-2.0
Repository
github
Last release
2 years ago

dojot-module-logger

This component is a simple logger, based on winston, that offers an endpoint to be added to an Express application.

How to use

It's simple. Just import it and use it:

   const DojotLogger = require("@dojot/dojot-module-logger-nodejs");
   DojotLogger.logger.debug("This is an example", {filename: "my_module"});

You can change its current log level by calling:

   DojotLogger.logger.setLevel("info");

You should definitely check out winston documentation for more information about how to use it.

You can add an endpoint to your component as well:

   var bodyParser = require("body-parser");
   var express = require("express");
   var app = express();

   app.use(bodyParser.json());
   app.use(DojotLogger.getHTTPRouter());
   app.listen(10001, () => {
       DojotLogger.logger.info(`Listening on port 10001.`);
   });

Thus you can call:

   curl -X PUT http://localhost:10001/log -H "Content-Type:application/json" -d '{"level" : "debug"}'

to change current log level. Currently supported levels are:

  • debug
  • info
  • warn
  • error

In order to get current log level, just send a GET request to the same endpoint:

   curl -X GET http://localhost:10001/log