All files / src/server/platform version.server.ts

100% Statements 3/3
75% Branches 3/4
100% Functions 2/2
100% Lines 3/3

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22              9x 9x               9x          
// Which code is running: the deployed Worker version and its tag, the git
// commit CI deploys with (`wrangler deploy --tag`). Locally the tag is empty.
import { env } from 'cloudflare:workers'
import type { LogFields } from '#/server/log/log'
import { createLogger, isLogLevel } from './logger.server'
 
export function workerVersion(): LogFields {
  const { id, tag } = env.CF_VERSION_METADATA
  return { versionId: id, commit: tag || undefined }
}
 
/**
 * The logger for the current request, with the version on every line and
 * LOG_LEVEL (wrangler.jsonc) as its threshold: debug locally, info deployed.
 */
export function createRequestLogger() {
  return createLogger({
    base: workerVersion(),
    minLevel: isLogLevel(env.LOG_LEVEL) ? env.LOG_LEVEL : 'info',
  })
}