How to Forward Logs

Functions are blocks of code that run on demand without the need to manage any infrastructure. Develop on your local machine, test your code from the command line (using doctl), then deploy to a production namespace or App Platform — no servers required.


You can configure functions to forward console and error logs from the function to a third-party logging service. Functions supports Papertrail, Datadog, and Logtail.

To configure your function to ship logs to a third party, you need to define a LOG_DESTINATIONS environment variable for it. This environment variable goes in your project.yml file and contains a JSON string with details on the log forwarding destination.

The JSON string is a JSON version of the log_destinations field of App Platform’s App Spec YAML file. You may use the App Spec reference for more details on the configuration required.

Note
In App Platform, you configure Papertrail using a syslog endpoint. Functions requires an HTTP source token when using Papertrail.

Examples

The following examples show how to configure the LOG_DESTINATIONS environment variable in your project.yml file. The LOG_DESTINATIONS line belongs under an environment: key at whichever scope is appropriate for your situation: project, package, or function. See the project.yml reference for more information about scopes and setting environment variables.

Papertrail

For Papertrail, create a log destination that accepts token-based authentication over HTTPS. This setting is under the Accept connections via… heading on Papertrail’s Create Log Destination page. Refer to Papertrail’s log destinations documentation for more details.

Use the provided token in your configuration:

LOG_DESTINATIONS:'[{"papertrail":{"token":"<your-log-destination-token>"}}]'

Datadog

For Datadog, the configuration requires an endpoint URL and an API key:

LOG_DESTINATIONS:'[{"datadog":{"endpoint":"https://http-intake.logs.datadoghq.com","api_key":"<your-api-key>"}}]'

Logtail

For Logtail, create an HTTP source and use the resulting token for the configuration:

LOG_DESTINATIONS:'[{"logtail":{"token":"<your-http-source-token>"}}]'

Multiple Destinations

The LOG_DESTINATIONS JSON structure is a list, so you can configure multiple log destinations:

LOG_DESTINATIONS:'[{"papertrail":{"token":"<your-http-source-token>"}},{"logtail":{"token":"<your-http-source-token>"}}]'