Log Service is an all-in-one service for log data. It supports log collection, consumption, shipping, query, and analysis. After Log Service is enabled on Knative, it enables you to manage and maintain serverless applications with higher efficiency.

Prerequisites

Procedure

  1. Collect logs of the Helloworld service.
    1. Log on to the Log Service console and click the target project. Create a Logstore named helloworld. For more information, see Manage a Logstore.
    2. Click the icon in the Data Import Wizard column and the helloword-log page appears.
    3. In the Third-party Software section, choose Docker Standard Output and the Specify Collection Mode page appears.
    4. Enter the configuration name and configure the plug-in. Then click Next.
      In this example, set the environment variable as follows: "K_SERVICE": "helloworld-go". Besides, use processors to process log data, such as "Keys": [ "time","level", "msg" ]. The detailed configuration is as follows:
      {
        "inputs": [
          {
            "detail": {
              "IncludeEnv": {
                "K_SERVICE": "helloworld-go"
              },
              "IncludeLabel": {},
              "ExcludeLabel": {}
            },
            "type": "service_docker_stdout"
          }
        ],
        "processors": [
          {
            "detail": {
              "KeepSource": false,
              "NoMatchError": true,
              "Keys": [
                "time",
                "level",
                "msg"
              ],
              "NoKeyError": true,
              "Regex": "(\\d+-\\d+-\\d+\\s+\\d+:\\d+:\\d+)\\s+(\\w+)\\s+(. *)",
              "SourceKey": "content"
            },
            "type": "processor_regex"
          }
        ]
      }
    5. Go to the Apply to Server Group page, select the target project, and click Apply to Server Group.
    6. On the Custom page, enable Full Text Index Attributes and set Key/Value index attributes. Then click Next.
    7. On the Shipper & ETL page, click Confirm.
  2. Run the following command to access the Hello World service.
    Logs will be generated.
    $ curl -H "Host: helloworld-go.default.example.com" http://112.124.XX.XX
    Hello Knative!
  3. On the Logstores page, find the target Logstore and click Search to view log information.
  4. Configure search conditions.
    For more information, see Real-time analysis.

    You can modify Column Settings to specify the columns to be displayed. In the following example, three columns are displayed: level, msg, and time.

Summary

The preceding example demonstrates how to use Log Service to collect logs of serverless applications in Knative. Log Service provides a comprehensive solution for log collection and analysis on Knative, and makes it easy to manage and maintain serverless applications running in the production environment.