Logging

I'm wondering what others are using for application level logging? Just console.log ? I woud like to enable some custom logging statements based on the environment, like log.debug, log.warn Has anyone tries libraries like Winston or Pino on workers? Is there a recommendation?
5 Replies
DaniFoldi
DaniFoldi7mo ago
Cloudflare recently acquired Baselime, which has become a popular option. Quite a few of us (including me) also use Axiom, and there are others that sometimes require more or less work to get it going. Honeycomb, datadog, etc - I recommend using otel-cf-workers for observability, and a custom log wrapper that also logs to console.log and sends to something like axiom for use later
laurent
laurent7mo ago
Thanks @Purple Blob | Green, any recommendations / ideas for next-on-pages logging?
DaniFoldi
DaniFoldi7mo ago
I'm afraid that for pages it will be a rather manual process; pages doesn't support logpush, so that's out, and (since you're asking for a recommendation, I can only recommend services I've tried) the next best option is probably manual logging with a library; vercel integrations wouldn't help you For Axiom specifically, Pino and https://www.npmjs.com/package/@axiomhq/pino might work, or just using the @axiomhq/js package directly. Important things to consider: - your service should not break if your logs aren't being delivered - your responses shouldn't be waiting on logs to be delivered, see ctx.waitUntil - you should try to batch logs (1000 subrequest limit), this is what libraries are great for so you don't have to manually manage this
Marcel Overdijk
Marcel OverdijkOP7mo ago
thx @Purple Blob | Green , for the wrapper to console.log any recommendation? like winston or pino? in my code I would like to do something like log.debug('..') and that should only be logged in development; no need for that to be loggede on cloudflare (production) or are libraries like winston to heave on a serverless env? that logs will be stored on other system , is something I will look into later (like logpush) I'm coming from a Java world where slf4j is quite the defacto standard. I wonder what that now is for envs like cloudflare
DaniFoldi
DaniFoldi7mo ago
for a logger, I recommend pino, and if you want to exclude it from your production builds, you can use the define feature or wrangler: https://developers.cloudflare.com/workers/wrangler/configuration/#non-inheritable-keys with something like DEBUG && console.log(...) if you define DEBUG to be truthy, it will execute the log, if it's falsy, it will skip, and the entire call will be removed from minified builds for workers, logpush is a good transport solution, since it takes care of console.log, exceptions, request metadata automatically, you just need to set up a destination
Want results from more Discord servers?
Add your server