# Cloudflare Pages

Cloudflare Pages is a frontend app development platform. Baselime enabled your to capture the server-side logs of your applications deployed on Cloudflare pages.

You can setup logs for Cloudflare Pages Functions in 4 steps.

Step 1: Install the @baselime/edge-logger package.

npm i -S @baselime/edge-logger

Step 2: Add the logger to your server-side code in the functions directory

import { BaselimeLogger } from "@baselime/edge-logger"

export function onRequest(context) {
  const logger = new BaselimeLogger({
    service: "your-service-name"
    namespace: context.request.url
    apiKey: context.env.BASELIME_API_KEY,
    ctx: context,
    isLocalDev: context.env.IS_LOCAL

  logger.info("Hello from the serverless world!", { data: { userId: 'random-id' } });

  return new Response(JSON.stringify({
    message: "Hello from the serverless world!"

Step 3: Add the BASELIME_API_KEY environment variable to your Cloudflare pages settings and deploy your application

Add Env to Cloudflare Pages
Add Env to Cloudflare Pages

Step 4: View your logs in the Baselime Console

# Special cases

There are special cases for instrumenting applications on Cloudflare Pages depending on the web framework.

# SvelteKit

Additional steps are necessary to instrument applications developed with SvelteKit.

Step 1: Update the build and deploy scripts in your project package.json

  "name": "my-svelte-app",
  "scripts": {
  	"build": "CF_PAGES=1 vite build",
    "deploy": "npm run build && wrangler pages deploy .svelte-kit/cloudflare",

Step 2: Add the Baselime logger to your hook.server.js file

import { BaselimeLogger } from "@baselime/edge-logger";

export const handle = async ({ event, resolve }: { event: any, resolve: any}) => {
  const baselimeApiKey = String(event.platform?.env?.BASELIME_API_KEY);

  const context = event.platform?.context || { waitUntil: () => {}, passThroughOnException: () => {} }
  const logger = new BaselimeLogger({
    service: 'your-service-name',
    namespace: event.request.url,
    apiKey: baselimeApiKey,
    isLocalDev: event.platform ? false : true,
    ctx: context
  event.logger = logger;

  const result = await resolve(event);

  return result;

Step 3: Access the Baselime logger in the server-side code

import type { BaselimeLogger } from '@baselime/edge-logger';

export async function load({ logger }) {
  logger.info("Hello from page.server.ts")
  return {
    data: Math.random(),
    message: "hello"