configureConsole
The configureConsole()
function allows configuring the behaviour of the console
global JS logger.
Syntax
configureConsole(loggingOptions)
Parameters
loggingOptions
: object- The name has to be between 1 and 254 characters inclusive.
- Throws a
TypeError
if the value is not valid. I.E. The value is null, undefined, an empty string or a string with more than 254 characters.
Examples
In this example, we disable prefixing for console.log
and use stderr
output for console.error
:
import { configureConsole } from "fastly:logger";
configureConsole({
prefixing: false,
stderr: true
});
async function handleRequest(event) {
console.log(JSON.stringify(event.request.headers));
const url = new URL(event.request.url);
try {
validate(url);
} catch (e) {
console.error(`Validation error: ${e}`);
return new Response('Bad Request', { status: 400 });
}
return new Response('OK');
}
addEventListener("fetch", (event) => event.respondWith(handleRequest(event)));