Skip to Content

Enable Logging Service for Your Application

test
0 %
Enable Logging Service for Your Application
Details

Enable Logging Service for Your Application

November 16, 2021
Created by
June 14, 2021
This tutorial shows you how to enable Logging Service for your application.

You will learn

  • How to access logs from command line window and SAP BTP cockpit
  • How to analyze logs using Kibana dashboard
  • How to enable Logging Service for your CAP application
  • How to test the Logging Service
QR code

To start with this tutorial use the result in the launchpad-service branch.


Step 1: Access logs from command line window
  1. Display recent logs.

    cf logs --recent <appname>
    
  2. Follow logs live.

    cf logs <appname>
    

Choose Ctrl + C to quit.

Which command is used to display application logs?
×

Step 2: Access logs from SAP BTP cockpit
  1. Enter your Global Account. If you’re using a trial account, choose Go To Your Trial Account.

  2. Choose Account Explorer.

  3. In the Subaccounts tab, choose the subaccount where you have deployed your service and application.

    Choose Subaccount
  4. Choose Cloud Foundry Spaces.

  5. Choose your space.

  6. Choose on the application whose logs you want to access.

  7. Choose Logs.

    App Logs

    Only the recent logs are displayed.

Log on to answer question

Step 3: Analyze logs using Kibana dashboard
  1. Go to your subaccount in SAP BTP cockpit.

  2. Choose Cloud Foundry Spaces.

  3. Choose your space.

  4. Choose the application whose logs you want to access.

  5. Choose Logs.

  6. Choose Open Kibana Dashboard.

    Kibana shows all logs.

    Although the Open Kibana Dashboard link is placed on the logs view of a particular application, it will give you access to the logs of all spaces where you have the required permission.

Log on to answer question

Step 4: Enable Logging Service

Logs are only kept for a short period and won’t be visible in Kibana without the Logging Service. By binding the Logging Service to your application, logs will be kept for longer and will be available for further analysis via Kibana.

It’s suggested to enable the Logging Service for all applications, so that error analysis will be possible even some hours after the incident.

In our experience, the development plan wasn’t sufficient for test scenarios. Probably, its okay for personal development spaces. However, this tutorial uses the standard plan to be on the safe side.

  1. Add an instance for the logging service to the resources section of your mta.yaml.
    ...
    resources:
    ...
    - name: cpapp-logs
      type: org.cloudfoundry.managed-service
      parameters:
        service: application-logs
        service-plan: lite
    
  2. Bind the logging service instance to the following modules of the mta.yaml.
    _schema-version: '3.1'
    ...
    modules:
      ...
      - name: cpapp-srv
        ...
        requires:
          ...
          - name: cpapp-logs
    
    _schema-version: '3.1'
    ...
    modules:
      ...
      - name: cpapp-db-deployer
        ...
        requires:
          ...
          - name: cpapp-logs
    

Logs are only kept for a short period and won’t be visible in Kibana without the Logging Service. By binding the Logging Service to your application, logs will be kept for longer and will be available for further analysis via Kibana.

It’s suggested to enable the Logging Service for all applications, so that error analysis will be possible even some hours after the incident.

In our experience, the development plan wasn’t sufficient for test scenarios. Probably, its okay for personal development spaces. However, this tutorial uses the standard plan to be on the safe side.

  1. Add an instance for the logging service to the resources section of your mta.yaml.

    ...
    resources:
    ...
    - name: cpapp-logs
      type: org.cloudfoundry.managed-service
      parameters:
        service: application-logs
        service-plan: standard
    
  2. Bind the logging service instance to the following modules of the mta.yaml.

    _schema-version: '3.1'
    ...
    modules:
      ...
      - name: cpapp-srv
        ...
        requires:
          ...
          - name: cpapp-logs
    
    _schema-version: '3.1'
    ...
    modules:
      ...
      - name: cpapp-db-deployer
        ...
        requires:
          ...
          - name: cpapp-logs
    
Log on to answer question

Step 5: Test it
  1. Build the MTAR file and deploy it to your Cloud Foundry space.

    mbt build -t ./
    cf deploy cpapp_1.0.0.mtar
    
  2. Open Kibana after successful deployment. Your org should now be visible in the Kibana dashboard.

    Kibana: Filter Org
  3. Choose the ( + ) icon to filter for it.

  4. The filter is added to the filter bar on the top of the screen and gets applied on the dashboard.

  5. You should see your newly applied applications.

    Kibana: Components

You can also browse all logs using the Discover button (compass icon) on the left navigation bar.
The available fields are displayed on the left side of the screen. You can add fields to the message display or quickly filter for any of the top values.

The time filter is on the right top of the screen. Don’t forget to choose Refresh.

Log on to answer question

The result of this tutorial can be found in the logging branch.

Give us 55 seconds of your time to help us improve


Next Steps

Back to top