Real-time logs
Logging is a fundamental building block supporting application development — it can provide insights during the initial stages of development and is often times crucial to understanding an issue occurring in production.
The Workers platform captures all console.log
’s and uncaught exceptions, in addition to information about the event itself.
By default a Worker will emit execution logs containing details about the Request, Response and related metadata.
In addition, you can add custom logs throughout your code. Any console.log
statements within your Worker will be visible in the dashboard or wrangler tail
. The following example demonstrates a custom console.log
within a Worker request handler.
After you deploy the above code, view the real-time logs in the dashboard or wrangler tail
.
To view real-time logs associated with any deployed Worker using the Cloudflare dashboard:
- Log in to the Cloudflare dashboard ↗ and select your account.
- In Account Home, go to Workers & Pages.
- In Overview, select your Worker > and select Logs.
To view real-time logs associated with any deployed Worker using Wrangler:
- Go to your Worker project directory.
- Run
npx wrangler tail
.
This will log any incoming requests to your application available in your local terminal.
The output of each wrangler tail
log is a structured JSON object:
By piping the output to tools like jq
↗, you can query and manipulate the requests to look for specific information:
You can customize how wrangler tail
works to fit your needs. Refer to the wrangler tail
documentation for available configuration options.
Note that:
- Workers logs are not stored. You can start and stop the stream at any time to view them, but they do not persist.
- If your Worker has a high volume of traffic, the real-time logs might enter sampling mode. This will cause some of your messages to be dropped and a warning to appear in your logs.
- Logs from any Durable Objects your Worker is using will show up in the dashboard.
- A maximum of 10 clients can view a Worker’s logs at one time. This can be a combination of either dashboard sessions or
wrangler tail
calls.
Logs can be persisted in two ways:
Workers Logpush allows you to send Workers Trace Event Logs to a supported destination. Worker’s Trace Events Logpush includes metadata about requests and responses, unstructured console.log()
messages and any uncaught exceptions.
Refer to the Workers Logpush documentation to learn how to create and configure Logpush jobs.
Tail Workers allow you to automatically invoke Tail Workers after the invocation of a producer Worker (the Worker the Tail Worker will track) that contains the application logic. It captures events after the producer has finished executing. You can filter, change the format of the data and send events to any HTTP endpoint.
Refer to the Tail Workers documentation to learn how to create and configure Tail Workers.
- Errors and exceptions - Review common Workers errors.
- Local development and testing - Develop and test you Workers locally.
- Logpush - Learn how to push Workers Trace Event Logs to supported destinations.
- Tail Workers - Learn how to attach Tail Workers to transform your logs and send them to HTTP endpoints.
- Source maps and stack traces - Learn how to enable source maps and generate stack traces for Workers.