@marianoleonardo/dojot-module-logger
TypeScript icon, indicating that this package has built-in type declarations

0.1.1 • Public • Published

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 

Readme

Keywords

Package Sidebar

Install

npm i @marianoleonardo/dojot-module-logger

Weekly Downloads

0

Version

0.1.1

License

Apache-2.0

Unpacked Size

39.6 kB

Total Files

15

Last publish

Collaborators

  • marianoleonardo