Streaming App Logs to Log Management Services
Page last updated:
This topic describes how to drain logs from Cloud Foundry to a third-party log management service.
Cloud Foundry aggregates logs for all instances of your apps as well as for requests made to your apps through internal components of Cloud Foundry. For example, when the Cloud Foundry Router forwards a request to an app, the Router records that event in the log stream for that app. Run the following command to access the log stream for an app in the terminal:
$ cf logs YOUR-APP-NAME
If you want to persist more than the limited amount of logging information that Cloud Foundry can buffer, drain these logs to a log management service.
For more information about the systems responsible for log aggregation and streaming in Cloud Foundry, see App Logging in Cloud Foundry.
Your Cloud Foundry marketplace may offer one or more log management services. To use one of these services, create an instance of the service and bind it to your app with the following commands:
$ cf create-service SERVICE PLAN SERVICE-INSTANCE $ cf bind-service YOUR-APP YOUR-LOG-STORE
For more information about service instance lifecycle management, see the Managing Service Instances topic.
Note: Not all marketplace services support syslog drains. Some services implement an integration with Cloud Foundry that enables automated streaming of app syslogs.
If a compatible log management service is not available in your Cloud Foundry marketplace, you can use user-provided service instances to stream app logs to a service of your choice.
You can install and use the CF Drain CLI Plugin to create and manage user-provided syslog drains from the CF command-line interface (cf CLI).
You may need to prepare your log management service to receive app logs from Cloud Foundry. For specific instructions for several popular services, see Service-Specific Instructions for Streaming App Logs. If you cannot find instructions for your service, follow the generic instructions below.
Complete the following steps to set up a communication channel between the log management service and your Cloud Foundry deployment:
Obtain the external IP addresses that Pivotal Web Services assigns to outbound traffic.
Provide these IP addresses to the log management service. The specific steps to configure a third-party log management service depend on the service.
Whitelist these IP addresses to ensure unrestricted log routing to your log management service.
Record the syslog URL provided by the third-party service. Third-party services typically provide a syslog URL to use as an endpoint for incoming log data. You use this syslog URL in Step 2: Create a User-provided Service Instance.
Cloud Foundry uses the syslog URL to route messages to the service. The syslog URL has a scheme of
https, and can include a port number. For example:
You can create a syslog drain service and bind apps to it using either generic Cloud Foundry Command Line Interface (cf CLI) commands, or drain-specific commands enabled by the CF Drain plugin for the cf CLI.
Each option is described below.
If the CF Drain CLI Plugin is not installed on your local workstation, follow the Installing Plugin instructions in the plugin source repository.
Decide whether to bind the drain to a single app or all apps in a space, and run the corresponding command:
cf drain APP-NAME SYSLOG-DRAIN-URL
APP-NAMEis name of the app to stream logs from
SYSLOG-DRAIN-URLis the syslog URL from Step 1: Configure the Log Management Service
All apps in a space:
cf drain-space --drain-name DRAIN-NAME --drain-url SYSLOG-DRAIN-URL --username USERNAME
DRAIN-NAMEis the name of the app to stream logs from.
SYSLOG-DRAIN-URL: The syslog URL from Step 1: Configure the Log Management Service.
USERNAME: Username to use when pushing the app. If you do not specify a username, you must have admin permissions because the plugin will create a user.
After a short delay, logs begin to flow automatically.
Note: To bind a drain to all apps in a space with a single command, you must use the CF Drain CLI Plugin as described in the previous section.
To create the service instance, run
cf cups) with the
-lflag, filling in values as follows:
To bind an app to the service instance, do one of the following:
cf pushwith a manifest. The services block in the manifest must specify the service instance that you want to bind.
$ cf bind-service YOUR-APP-NAME DRAIN-NAME
After a short delay, logs begin to flow automatically.
Refer to Managing Service Instances with the CLI for more information.
To verify that logs are draining correctly to a third-party log management service:
Take actions that produce log messages, such as making requests of your app.
Compare the logs displayed in the CLI against those displayed by the log management service.
For example, if your app serves web pages, you can send HTTP requests to the app. In Cloud Foundry, these generate Router log messages, which you can view in the CLI. Your third-party log management service should display corresponding messages.
Note: For security reasons, Cloud Foundry apps do not respond to
ping. You cannot use
ping to generate log entries.
The CF Drain CLI plugin extends the cf CLI by adding simple commands for user-provided syslog drains. Also, you can use the plugin to bind all apps in a space to a syslog drain. This option includes app, space, and org names in the drain. It also binds any new apps pushed to the space.
Installation: To install the CF Drain CLI plugin see the Installing Plugin instructions in the plugin source repository.
Commands: The plugin adds commands for creating, deleting, and listing syslog drains, and for binding apps to the drains. See the Usage section of the plugin source repository for details.