Unitech / Unitech/pm2

Message in JSON logs is not stringified

Open
#5,244 0 comments 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.