如何获取已部署的app的debugging日志?
PROBLEM
Things are not working and you want more insight into what may be happening with your application that won't start, won't deploy, or has recently failed in some way.
STEPS
There are several things you could do to prepare for the situation where your app and services start to misbehave.
(a) Turn on Cloud Foundry Tracing for the CLI to get logs of staging and buildpack issues during REST API calls.
For bash shells it might look like this:
export CF_TRACE=~/cf-trace.log
or for csh/tcsh:
setenv CF_TRACE ~/cf-trace.log
You will receive a lot of details when you run cf commands from then on that will help you and others debug what might be happening.
(b) Use the cf logs and cf logs --recent commands.
The cf logs will start streaming / tailing log details from your application's STDOUT and STDERR as any output is generated by the app and container. If you want to just show past log output the --recent will dump anything still in the log buffer.
(c) Use the cf files command to download log files (for DEA apps).
From your running application some log files will persist to files in the container temporarily. You can see a list of them by running cf files <App Name> /logs and then download them one at a time: cf files <App Name> /logs/staging_task.log > staging_task.log.
(d) Create an instance of the logstash logging service.
https://www.predix.io/services/service.html?id=1184
See the logging documentation to bind the ELK stack: elastic search, logstash, and kibana for your application.
https://docs.predix.io/en-US/content/service/operations/logging/
(e) Make sure you send important logging information from your application. While the above steps will help you access the logs, if you aren't outputting anything to the logs it will have limited value.
This can range from simple print statements to more robust logging frameworks like log4j in Java, log4js in JavaScript, or logging in python that produce logs in parseable formats for easier analysis.
DEPENDENCIES
Cloud Foundry CLI
You can retrieve logs for your pushed apps/services, but you will not be able to see logs for the service instances which you depend on such as Time Series, Asset, or UAA.
RESOURCES
Logstash Logging Service Documentation
https://docs.predix.io/en-US/content/service/operations/logging/
Cloud Foundry Documentation for Troubleshooting Application Deployment and Health
https://docs.cloudfoundry.org/devguide/deploy-apps/troubleshoot-app-health.html
Pivotal Web Service Documentation for Application Logging in Cloud Foundry
https://docs.run.pivotal.io/devguide/deploy-apps/streaming-logs.html