0.2.0 • Published 2 years ago

workers-logger v0.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

⚡️ 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

0.2.0

2 years ago

0.1.0

2 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.6

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago