Message in JSON logs is not stringified
Open
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 43.3k
- Forks
- 2.7k
- PR merge metrics
- No merged PRs in 30d
Description
What's going wrong?
JSON logs dont support JSON data
How could we reproduce this issue?
Run any PM2 app with --json and console out an object. For example:
console.error({this: 'foo'})
Actual err log
{
"message":"{\n this: 'foo'\n}",
"timestamp":"2021-12-08T22:20:27",
"type":"err",
"process_id":0,
"app_name":"Log test ap"
}
Expected err log
{
"message":"{\"this\": \"foo\"}",
"timestamp":"2021-12-08T22:20:27",
"type":"err",
"process_id":0,
"app_name":"Log test ap"
}
Note: I formatted the above json objects to make them easier to read here. I would expect to see them all on one line as they are currently in my logs
EDIT:
I also noticed that the strout logs seem to be fine
out_file example
{
"message":"{\"level\":20,\"msg\":\"POST /test/endpoint (242 ms) 200\",\"pid\":16016,\"hostname\":\"ip-123-12-12-123\",\"v\":1}\n",
"timestamp":"2021-12-10T01:14:05.145Z",
"type":"out",
"process_id":0,
"app_name":"Jobs Marketplace Log test ap"
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running any PM2 app with --json and console.error({this: 'foo'}), then compare the err and out log formats shown in the issue. The issue names no files or tests; done means err JSON logs encode the object as JSON in the message, preserve the surrounding fields, and remain on one line.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- observability
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100