Payload does not log context in log messages

default discord avatar
Journeyman301
4 months 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 🙂

  • discord user avatar
    jesschow
    Payload Team
    4 months ago

    Hi @Journeyman301! 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
    Payload Team
    4 months ago

    Hey @Journeyman301, just as @jesschow 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
    Journeyman301
    4 months 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 🙂

  • default discord avatar
    jarrod69420
    4 months ago

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

Open the post
Continue the discussion in Discord
Like what we're doing?
Star us on GitHub!

Star

Connect with the Payload Community on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.