Skip to content

autotelic/worker-logger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

worker-logger

A simple log handler for cloudflare workers.

Workers have limits on subrequests and simultaneous open connections, so if we are logging via http to an external service we want to batch log requests.

This logger creates a queue, and provides log level methods and a report method. Each log level method enqueues the message in CLEF format, report processes the queue of log messages by calling the configured reporter.

Installation

npm install --save @autotelic/worker-logger

Usage

import { Logger, createSeqReporter } from '@autotelic/worker-logger'

// this creates a reporter for posting to Seq https://docs.datalust.co/docs/posting-raw-events
// pass in the global fetch of the worker
const seqReporter = createSeqReporter('http://localhost:5341', fetch)


const log = new Logger(transports: [
  { reporter: seqReporter },
  { repoert: consoleReporter, batch: false },
])

addEventListener('fetch', event => {
  event.respondWith(handleEvent(event));
})

async function handleEvent(event) {
  log.info('hello logger')
  const response = new Response('Hello worker!', {
    headers: { 'content-type': 'text/plain' },
  })
  log.info('response constructed')
  event.waitUntil(log.report())
  return response
}

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •