How to configure logging output in json format?



  • Hello Guys,

    Please help us understand how to configure log output in json format or how to integrate JSreport logs with Kibana?



  • jsreport uses the winston logging package so pretty much everything you find out in the winston docs can be applied in the jsreport.
    https://jsreport.net/learn/configuration#logging

    To enable json for all transports, add a default logging config to jsreport.config.json.

     "logger": {
        "console": {
          "transport": "console",
          "level": "debug"
        },
        "file": {
          "transport": "file",
          "level": "debug",
          "filename": "logs/log.txt"
        },
        "error": {
          "transport": "file",
          "level": "error",
          "filename": "logs/error.txt"
        }
      },
    

    And the update the app server.js file with the following. It will instruct all transports to format in json.

    const jsreport = require('jsreport')()
    
    if (process.env.JSREPORT_CLI) {
      // export jsreport instance to make it possible to use jsreport-cli
      module.exports = jsreport
    } else {
      jsreport.afterConfigLoaded(() => {
        const winston = require('winston')
        jsreport.logger.format = require('winston').format.combine(
          jsreport.logger.format,
          winston.format.json()
        )
      })
      jsreport.init().then(() => {
        // running
      }).catch((e) => {
        // error during startup
        console.error(e.stack)
        process.exit(1)
      })
    }
    
    

Log in to reply
 

Looks like your connection to jsreport forum was lost, please wait while we try to reconnect.