Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
514 views
in Technique[技术] by (71.8m points)

javascript - 了解Winston中的日志记录机制(To understand logging mechanism in winston)

I am writing a wrapper in winston.Im using logger.info() and logger.error().

(我正在用logger.info()和logger.error()在winston.Im中编写包装器。)

Im passing a custom object along with the message to logger.info().

(我将自定义对象以及消息传递给logger.info()。)

For example:

(例如:)

input:

(输入:)

logger.info(message,{className:myClass,Identifier:myIdentifier})

//{className:myClass,Identifier:myIdentifier} is my custom object

output

(输出)

{level:info,message:myMessage,className:myClass,Identifier:myIdentifier} 

In this case my output is kind of presentable.

(在这种情况下,我的输出是可呈现的。)

But when Im passing the custom object to logger.error() the format in which the log gets printed is not the same.

(但是当我将自定义对象传递给logger.error()时,日志的打印格式是不同的。)

For example:

(例如:)

input:

(输入:)

logger.info(message,{className:myClass,Identifier:myIdentifier,error:new Error()})

//{className:myClass,Identifier:myIdentifier,error:new Error()} is my custom object in this case

output:

(输出:)

{level:info,message:myMessage, stack:'...my error stack...'} 

//Note that errors({stack:false}) was set as a format.

What I am expecting is:

(我期望的是:)

{level:info,message:myMessage,className:myClass,Identifier:myIdentifier,error:..my error stack...} 

How can I achieve this?

(我该如何实现?)

  ask by Dylan Rodriguez translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...