apps/docs/content/troubleshooting/inspecting-edge-function-environment-variables-wg5qOQ.mdx
Sometimes it can be informative to log values from your Edge Functions. This walks you through the process of logging environment variables for inspection, but it can be generalized for all logging.
Steps:
enable docker
Create a local Supabase project
npx supabase init
supabase folderecho "MY_NAME=Some_name" >> ./supabase/.env
npx supabase secrets set --env-file ./supabase/.env --project-ref <PROJECT REF>
npx supabase secrets list
For security reasons, it is not advised to log secrets, but you can log a truncated version just for the reassurance that they're being updated:
//logs the function call and the secrets
console.log('Hello from Functions!')
//custom secret
console.log('logging custom secret', Deno.env.get('MY_NAME'))
// default secrets
console.log('logging SUPABASE_URL:', Deno.env.get('SUPABASE_URL').slice(0, 15))
Deno.serve(async (req) => {
const { name } = await req.json()
const data = {
message: `Hello ${name}!`,
}
return new Response(JSON.stringify(data), { headers: { 'Content-Type': 'application/json' } })
})
After calling your function, you can check your edge function logs to observe the logged values. It should look something like this:
Note: search filters are case sensitive and must be present in the event message.
Note: excessively long JSON logs may be truncated. If this occurs, use the JSON.stringify() function to convert the JSON object into text. You can then copy and paste the log into a JSON beautifier.