Fast and effective logging for Cloudflare Workers.
This is free to use software, but if you do like it, consider supporting me ❤️
- Super light weight
- Custom Reporters
- Built on top of
diary
- Optimized to not hinder critical path
npm add workers-logger
import { track } from 'workers-logger';
addEventListener('fetch', (event) => {
const { request } = event;
const log = track(request);
log.info('gearing up to make a response');
const res = new Response('hi there');
event.waitUntil(log.report(res));
return res;
});
to see more visit examples
Returns log functions and our
.report
method.
Returns a promise with intended usage with event.waitUntil
. And thus in terns runs your
reporter
defined on track.
A reporter is a single function ran at then end of .report
. And gives
you the ability to send that data somewhere, or merely into
dashboard logs.
import type { Reporter } from 'workers-logger';
import { track } from 'workers-logger';
const reporter: Reporter = (events, { req, res }) => {
// do whatever you want
};
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;
});
example when sending into Logflare at /examples/workers/logflare
MIT © Marais Rossouw