添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
从容的椰子  ·  [PostgreSQL]psql: ...·  1 月前    · 
朝气蓬勃的李子  ·  学院简介·  2 月前    · 
慷慨的汽水  ·  matplotlib 连续 画图-掘金·  9 月前    · 
坐怀不乱的跑步机  ·  常見問題·  1 年前    · 
Your browser does not seem to support JavaScript. As a result, your viewing experience will be diminished, and you have been placed in read-only mode . Please download a browser that supports JavaScript, or enable it if it's disabled (i.e. NoScript).

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?

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

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 :)