Cloudflare Pages is Cloudflare's 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 2: Add the logger to your server-side code in the functions directory
functions/index.js
import{ BaselimeLogger }from"@baselime/edge-logger"exportfunctiononRequest(context){const url =newURL(context.request.url);const logger =newBaselimeLogger({service:"your-service-name",namespace:`${context.request.method}${url.hostname}${url.pathname}`,apiKey: context.env.BASELIME_API_KEY,ctx: context,isLocalDev: context.env.IS_LOCAL});
logger.info("Hello from the serverless world!",{data:{userId:'random-id'}});
context.waitUntil(logger.flush());returnnewResponse(JSON.stringify({message:"Hello from the serverless world!"}));}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Remember to call logger.flush(), otherwise the execution will terminate before logs are forwarded to Baselime.
Step 3: Add the BASELIME_API_KEY environment variable to your Cloudflare pages settings and deploy your application