Socket
Book a DemoInstallSign in
Socket

@bug-fix/workers-logger

Package Overview
Dependencies
Maintainers
0
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bug-fix/workers-logger

A fast and effective logging framework for Cloudflare Workers

0.2.0-fix.1
latest
Source
npmnpm
Version published
Weekly downloads
0
Maintainers
0
Weekly downloads
 
Created
Source

workers-logger

fast and effective logging for Cloudflare Workers

downloads size

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

Keywords

logging

FAQs

Package last updated on 26 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.