Console
Designed based on the Web APIs standard Console API. The edge function runtime can use the
console
object to output debugging information and logs. The output content can be viewed and analyzed through web debugging operations, or the real-time log push feature can be used to achieve long-term log retention and query analysis.Description
console.log(val1)console.log(val1, /* …, */ valN)
console
object's other methods (info()
, notice()
, warn()
, error()
, debug()
) have the same syntax format.Parameter
Parameter Name | Type | Required | Description |
val1 | string | number | null | undefined | boolean | object | Symbol | Array<[string, string]> | Function | No | The first value to output. |
valN | string | number | null | undefined | boolean | object | Symbol | Array<[string, string]> | Function | No | Other values to output. |
Note:
In edge functions, the content output by
console
can be retained and analyzed through the real-time log push feature for long-term log retention and query analysis.1. In Function logs,
console
supports four levels: info, notice, warn, and error. console.log()
corresponds to the info level.2. In edge functions, custom log output content other than log, info, notice, warn, and error will not be recorded in Function logs.
3. The size limit for a single real-time log is 40KB, and the
console
output content size limit is 4KB. Exceeding the limit will result in truncation.Note:
1. In a single edge function, it is recommended to limit each
console
content length to 8k characters.2. In a single edge function, the Web debugging page displays a maximum of 20
console
outputs per request. Any console
output exceeding 20 will not be shown on the debugging page.Example Code
function handleEvent(event) {const { request } = event;const url = new URL(request.url);// Output basic informationconsole.log('Process request:', url.pathname);// Output prompt messageconsole.info('Request processing started');// Output attention informationconsole.notice('Request processing method:', request.method);// Output warning informationconsole.warn('Request parameters may be incomplete');// Output error informationconsole.error('Error occurred while processing the request');return event.respondWith(new Response('Hello World'));}addEventListener('fetch', event => {handleEvent(event);});
Sample Preview

Related Reference