workers-logger
workers-logger copied to clipboard
Also log to console
Howdy! Loving this minimalist lib for logging. On feedback I had is it'd still be nice if it logged to console by default and/or in addition to a report for Web Console and Wrangler scenarios where it'd still be reading logs from that source in real time.
Hey ππ» thank you so much βΒ glad its been useful for you. Yeah that's super helpful! And console logs are largely logged into the void, so no harm in doing it by default.
But in saying that, I don't really want to impose that for everyone, the library is designed to "bring your own reporter".
So can this work for you?
const reporter: Reporter = (events, { req, res }) => {
console.log(events); // π just add this line in your reporter.
// send events to your logging framework
};
addEventListener('fetch', (event) => {
const { request } = event;
const log = track(request, 'my-worker', reporter);
log.info('gearing up to make a response');
const res = new Response('hi there');
event.waitUntil(log.report(res));
return res;
});
Sorry π going back and forth on this idea. I think what makes sense is when there is no reporter, to just have a default one that logs to the console.
Ill action this one π
Admitting that workers should be very short lived and therefore it shouldn't matter that much, the only concern I have with that is it posts logs as a bundle rather than when they're immediately.