Simple logging in development

In development I want to be able to do some logging, like:
logger.debug('Fetching customer with id=%s', id);
logger.trace('Querying database for customer with id=%s', id);
logger.debug('Fetching customer with id=%s', id);
logger.trace('Querying database for customer with id=%s', id);
by default it's fine to have just debug, but sometimes I would also like to trace logs for more details. Besides the log message itself, I would like to log also automatically some context info, like the Hono request-id. I tried Pino js logger, but it gives some problems on Cloudflare workers, so I wonder if there are other (simple) solutions, or that I can better write my own?
2 Replies
ItsWendell
ItsWendell3mo ago
Hi Marcel, Is this purely for development? What's missing in the standard logging features console.log / console.debug etc that you would want in a logging library? For production I've been using https://axiom.co with a tail worker that pushes regular old console log's into Axiom. For Pino, you need to make sure you're using the 'web' version and not the 'node' version, since the node version isn't fully compatible.
Marcel Overdijk
Marcel OverdijkOP3mo ago
Thx Wendell, Indeed I used the browser version of Pino; but it gave me some strange - for me unexpected - behavior: https://github.com/pinojs/pino/issues/2035 Initially it's for development logging, but ideally I could also use it for production, perhaps with Cloudflare logpush. 2 things would be important: - run application with different log level enabled (e.g. prod with only info, dev with debug, but also be able to run dev with trace if needed) - provide some context to each log message automatically (e.g. a request id)
Want results from more Discord servers?
Add your server