Home

Awesome

<div align="left"> <samp>

workers-logger licenses

</samp>

Fast and effective logging for Cloudflare Workers.

<br> <br> <sup>

This is free to use software, but if you do like it, consider supporting me ❤️

sponsor me buy me a coffee

</sup> </div>

⚡️ Features

⚙️ Install

npm add workers-logger

🚀 Usage

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

🔎 API

track(request: Request, name?: string, reporter?: Reporter)

Returns log functions and our .report method.

report(response: Response)

Returns a promise with intended usage with event.waitUntil. And thus in terns runs your reporter defined on track.

Reporters

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

License

MIT © Marais Rossouw