llrt icon indicating copy to clipboard operation
llrt copied to clipboard

Unable to log in JSON structured format

Open nocquidant opened this issue 11 months ago • 1 comments

Hi, I am trying to follow: JSON logging option in the console

But the following code: console.log({ data: 12.3, flag: false });

Produces a single string instead of key-value pairs:

{
    "time": "2024-03-01T19:55:28.045Z",
    "requestId": "bf340645-6ed9-40a3-ae15-2a82dc83ec5d",
    "level": "INFO",
    "message": "{ data: 12.3, flag: false }"
}

nocquidant avatar Mar 01 '24 20:03 nocquidant

Hi @nocquidant! Thanks for the report. There seems to be a bit of inconsistent behavior with how Node.js outputs JSON log format in Lambda. I see now that if only 1 argument was passed to console.log it gets expanded and converted into json, if multiple are added, it's consistent with LLRT. I'm raising this with the service team.

Question: Ignoring how it works today, what would in your opinion be the best output for something like this? console.log({ data: 12.3, flag: false },"example",{obj2: 1});

richarddavison avatar Mar 01 '24 20:03 richarddavison

Fixed by: https://github.com/awslabs/llrt/pull/264

richarddavison avatar Mar 13 '24 06:03 richarddavison