You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
write logs both in console and files (with daily rotate)
write logs in console and files with this format: "timestamp - level - text message - json or string"
write in console with colours based on levels (everything must be coloured, both message and payload)
write json data in console and files in a readable and good way
write strings, number, arrays as second param of logger.debug. For instance: "00000 - warn - hello - [1,2,4]". In this example I'm logging an array and not a json.
info: Hello again logs with a small object {"pippo":{"pluto":"hello","ooo":2.4,"sasas":[1,2,3],"ole":{"test":true}},"timestamp":"2019-06-26 12:33:55"}
with this 'crazy' "timestamp":"2019-06-26 12:33:55" inside my json payload.
So, I should do something like "format.printf(info => myFunction(info))", for instance "format.printf(info => ${info.timestamp} ${info.level}: ${info.message})
)," to do this,
but how can I combine format.simple() and format.printf without breaking json logger and logging on file like this: "timestamp - level - text message - json or string"?
I also tried to implement a custom logic to remove Symbol and other stuff from the object in format.printf, but it's quite complicated and probably inefficient. Which is the right way to do this?
Do you have any suggestions? Am I missing something or is there an issue somewhere?
Also, about point 3 of the list above, how to color everything in console with the json data?
Thanks
The text was updated successfully, but these errors were encountered:
Ks89
changed the title
How to use json logger with timestamp, console + file and log also non-json data
How to use json logger with timestamp, console + file and log also non-json data?
Jun 26, 2019
Also, if not available, is there a format.something() to print json, level and timestamp by default? I think that a log without timestamps it's a little bit useless
I've come across what seems to be a pretty severe issue with Winston and defining multiple transports on a logger: #1933. I think you may be running into the same issue. For the record, it is possible to have different formats per transport.
When creating a logger, you can set a "base" or "global" format. For example, when creating the logger, I set the format option to format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss.SSSZZ' }). Then, for each transport, I define another format (or, in my case, a pipeline of formatters via format.combine(...). It appears (I haven't looked at winston's source code yet for this) that Winston will format.combine the logger format with the transport formatter(s), resulting in the final output. Just beware that there appears to be a fairly significant issue with using multiple transports in combination with log entry metadata that you pass in. Only the first transport will get the metadata. The metadata gets silently dropped for all subsequent transports.
Please tell us about your environment:
winston
version?winston@2
winston@3
node -v
outputs: 10.15.1What is the problem?
I'm trying to use winston 3 to log in this way:
How can I do that? This is my current code:
If you try to run this code you can't achieve all requirements, for instance point 5 is not working.
Also, if I try to enable timestamps with:
the result is a log like this:
with this 'crazy' "timestamp":"2019-06-26 12:33:55" inside my json payload.
So, I should do something like "format.printf(info => myFunction(info))", for instance "format.printf(info =>
${info.timestamp} ${info.level}: ${info.message}
))," to do this,
but how can I combine format.simple() and format.printf without breaking json logger and logging on file like this: "timestamp - level - text message - json or string"?
I also tried to implement a custom logic to remove Symbol and other stuff from the object in format.printf, but it's quite complicated and probably inefficient. Which is the right way to do this?
Do you have any suggestions? Am I missing something or is there an issue somewhere?
Also, about point 3 of the list above, how to color everything in console with the json data?
Thanks
The text was updated successfully, but these errors were encountered: