New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@intheroomglobal/cf-worker-logger

Package Overview
Dependencies
Maintainers
0
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@intheroomglobal/cf-worker-logger

Configurable Cloudflare Worker logger that allows sending logs to destination of choice

  • 0.5.0
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
2
decreased by-71.43%
Maintainers
0
Weekly downloads
 
Created
Source

Cloudflare Worker Logger

A re-usable logger for use in Cloudflare Workers. Extend the class to add custom event transforms and transports. Allows logs to be sent to any destination. In worker environments waitUntil is called automatically when logging.

Installation

npm i -S @intheroomglobal/cf-worker-logger

Usage

Extend the logger to transform events as you require and to send to your logging endpoint:

import Logger, { type LogEvent } from '@intheroomglobal/cf-worker-logger';

type Env = {
  LOGS_URL: 'http://my.logging.service',
  LOGS_TOKEN: 'myapitoken'
}

export class MyLogger extends Logger<Env> {
  transformEvent(event: LogEvent) {
    return {
      ...event,
      my: {
        custom: 'fields'
      }
    };
  }

  send(event: LogEvent) {
    return fetch(this.env.LOGS_URL, {
      method: 'POST',
      headers: {
        'authorization': `Bearer ${this.env.LOGS_TOKEN}`
      },
      body: JSON.stringify(event)
    });
  }
}

  1. Log requests and responses:
export default {
  async fetch(request, env, context) {
    const logger = new MyLogger(request, env, context);
    const start = Date.now();
    const response = new Response('Hello, World!', { status: 200 });
    logger.logResponse(response, Date.now() - start);
    return response;
  }
}
  1. Attach a logger to requests:
import Logger from '@foreverholdings/logflare-logging';

export default {
  async fetch(request, env, context) {
    request.logger = new Logger(request, env, context);
    return handleRequest(request);
  }
}

function handleRequest(request) {
  request.logger.info('Returning a greeting');
  return Response('Hello, World!', { status: 200 });
}

FAQs

Package last updated on 03 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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc