How to use format options for logging



  • Hi all,
    I want to use winston format printf, timestamp, etc. to give the report logging (nodejs: jsreport-core) the same look than the rest of my app. I tried a lot, but can not find a solution. I was not able to add the existing winston loggin of the app, nor use format options within the extensions options.

    Any help here?


  • administrators

    hi! can you share the code that you are trying to use to customize the format? i have a feeling that this is not supported however since we allow custom transports it should probably work if you instantiate the transport by your own and specify the formatter options.

    PD: jsreport uses winston v2, so keep in mind that when working with the winston api, we will update to the latest winston v3 in jsreport v3, which is currently in development



  • thx for your answer.

    I tried

    "logger": {
       "console": 	{ "transport": "console", "level": "debug", "format": winston.format.combine(winston.format.timestamp({format: 'YYYY-MM-DD HH:mm:ss'}),winston.format.json(),winston.format.printf(function(info){return info.timestamp.toString()+' > '+info.message}))}
    }
    

    and also

    const winston = require('winston')
    jsreport.logger.add(winston.transports.Console, { level: 'info' })
    

    first example causes no changes and the second one did not work, as i know now, because of version 3 of winston i uses within my app. I will try the timestamp and formatter option of version 2 of winston later this day and will see, if get an other result.



  • I'm in a hurry, so quick:

    "logger": {
        "console": 	{ "transport": "console", "level": "debug",  "timestamp": function() {return Date.now()},  formatter: function(options) {return options.timestamp() + ' ' +options.level.toUpperCase() + ' ' +(options.message ? options.message : '') +(options.meta && Object.keys(options.meta).length ? '\n\t'+ JSON.stringify(options.meta) : '' );
      }}
    }
    

    worked fine. Thx for the info about version 2 :)



  • Remark: Worked fine with console, same options not working with file logging.


Log in to reply
 

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