javascript - Winston logger not being printed on new line - Stack Overflow

This is my winston logger - var winston = require('winston')var logger = new (winston.Logger)

This is my winston logger -

var winston = require('winston')

var logger = new (winston.Logger)({
  transports: [
    new (winston.transports.File)({
      // log which takes care of all the MAS scoring - node clusters and servers
      filename: './test.log',
      level: 'info',
      json: true,
      eol: 'rn'
    })
  ]
})

And when I run the actual logger:

logger.info('hi', 'it meeeeee')
logger.info('hi', 'it youuuuuu')

It prints out like this in the test.log file -

{"level":"info","message":"hi it meeeeee","timestamp":"2016-08-18T08:42:01.768Z"}rn{"level":"info","message":"hi it youuuuuu","timestamp":"2016-08-18T08:42:01.770Z"}rn

And I want it to be like this:

{"level":"info","message":"hi it meeeeee","timestamp":"2016-08-18T08:42:01.768Z"}
{"level":"info","message":"hi it youuuuuu","timestamp":"2016-08-18T08:42:01.770Z"}

How is this possible? I have read this question Node.js winston logger; How to start from a newline when insert log into log file? - however it does not solve the issue in my case.

I.e. if I open in Notepad ++, mand line or Sublime text I still get the same issue.

This is my winston logger -

var winston = require('winston')

var logger = new (winston.Logger)({
  transports: [
    new (winston.transports.File)({
      // log which takes care of all the MAS scoring - node clusters and servers
      filename: './test.log',
      level: 'info',
      json: true,
      eol: 'rn'
    })
  ]
})

And when I run the actual logger:

logger.info('hi', 'it meeeeee')
logger.info('hi', 'it youuuuuu')

It prints out like this in the test.log file -

{"level":"info","message":"hi it meeeeee","timestamp":"2016-08-18T08:42:01.768Z"}rn{"level":"info","message":"hi it youuuuuu","timestamp":"2016-08-18T08:42:01.770Z"}rn

And I want it to be like this:

{"level":"info","message":"hi it meeeeee","timestamp":"2016-08-18T08:42:01.768Z"}
{"level":"info","message":"hi it youuuuuu","timestamp":"2016-08-18T08:42:01.770Z"}

How is this possible? I have read this question Node.js winston logger; How to start from a newline when insert log into log file? - however it does not solve the issue in my case.

I.e. if I open in Notepad ++, mand line or Sublime text I still get the same issue.

Share Improve this question edited May 23, 2017 at 12:16 CommunityBot 11 silver badge asked Aug 18, 2016 at 8:46 user6700780user6700780 1
  • It is true what Ramesh said. Winston allows you to add any STRING! to "end of the line" (which is considered at each log input). You added two letters "rn" at the end, therefore it does exactly what is supposed to. The "r" and "\r" are different characters. PS: Do you need to change eol at all? Most modern programs can open and edit both - windows and linux styles documents... Which means I would suggest to just delete the line with eol (or use Ramesh solution, if you insist on windows-like end of line) – libik Commented Aug 18, 2016 at 9:06
Add a ment  | 

1 Answer 1

Reset to default 5

Try this eol: \r\n

Look official documentation

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744347141a4569752.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信