Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

Payload does not log context in log messages

default discord avatar
journeyman3012 years ago
4

Hello there,



First of all, I want to thank you for your work with this CMS. It's really awesome and saved my life 😄



I've just noticed that logging lacks the context. E.g.:


payload.logger.info(`Payload started`, {
  adminURL: payload.getAdminURL(),
})

The above log produces the following message:


{"level":"info","time":1683870398987,"pid":41235,"hostname":"my-computer.local","name":"payload","msg":"Payload started"}


However, if I do the following:


payload.logger.info({
  adminURL: payload.getAdminURL(),
}, `Payload started`)


It will log the context and the message correctly:


{"level":"info","time":1683870076527,"pid":41071,"hostname":"my-computer.local","name":"payload","adminURL":"http://localhost:3000/eabs","msg":"Payload started"}


This would not be a problem for me, but it is a problem, because within the payload cms itself, the context is not being logged (e.g. when I can't send a mail:

https://github.com/payloadcms/payload/blob/29a0dcffc749269409c0fab649a1f3ce1dc06b83/src/email/sendEmail.ts#L10C1-L13

).



Is there something I'm missing?



Payload version: 1.8.2


Steps to reproduce:


1.

npx create-payload-app test-logging

(Select blank)


2.

cd test-logging

3. Open up

src/server.ts

and change the log within the

onInit

to:

payload.logger.info('Payload started', { adminURL: payload.getAdminURL() })

4.

npm run dev

5. See that the log does not include the

adminURL

Thank you for your help in advance 🙂

  • default discord avatar
    jessrynkar2 years ago

    Hi

    @349223475933872130

    ! We're glad you like Payload and thank you for the kind words 🫶



    I can reproduce the issue you're having, and it looks like the pino docs are sending the message in second aswell

    https://getpino.io/#/docs/api?id=info

    Going to test out that email error also and will get back to you!

  • discord user avatar
    patrikkozak
    2 years ago

    Hey

    @349223475933872130

    , just as

    @854377910689202256

    pointed out - Pino is expecting

    messages

    as the second argument. I went ahead and opened a PR that adjusts the

    logger.error

    call in

    sendEmail.ts

    to have

    err

    called first,

    message

    second.



    I will let you know when this is merged! Thanks for bringing this to our attention!



    https://github.com/payloadcms/payload/pull/2663
  • default discord avatar
    journeyman3012 years ago

    Awesome, thank you guys. However, it would worth a shot to double check all of the loggings. If I'll have time during the weekend, I'll check and open a PR if needed 🙂

  • discord user avatar
    jarrod_not_jared
    2 years ago
    @349223475933872130

    I checked the entirety of the repo when working with pat on this one. Funny this was the only spot 👍

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.