Log Service is an all-in-one service to manage log data. Log Service allows you to
collect, consume, ship, query, and analyze log data without development work. After
Log Service is enabled on Knative, you can manage and maintain serverless applications
with higher efficiency.
Procedure
- Collect log data of the Helloworld application.
- Log on to the Log Service console.
- In the Projects section, click Create Project to create a Log Service project named helloworld. For more information, see Manage a Logstore.
- Click the created helloworld project.
- Navigate to the details page of the project. In the upper-right corner of the page,
click Import Data.
- In the Import Data dialog box, find and click Docker Standard Output to navigate to the Docker Standard Output page.
- In the Specify Logstore step, select the created Logstore and click Next.
- Configure Create Machine Group.
- Click Complete Installation.
- Configure Machine Group Settings.
- Configure Specify Data Source.
In the plug-in configuration, specify the following environment variable for log collection:
"K_SERVICE": "helloworld-go"
. Use processors to process log data, for example,
"Keys": [ "time","level", "msg" ]
. The following code block is an example:
{
"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"
}
]
}
- After the data source is configured, click Next.
- In the Configure Query and Analysis step, enable Full Text Index and set key/value index attributes.
- Click Next to proceed to the End page.
- Run the following command to access the Helloworld application.
The following log data is generated:
curl -H "Host: helloworld-go.default.example.com" http://112.124.XX.XX
Expected output:
Hello Knative!
- Go to the details page of the helloworld project. On the details page, find the created
Logstore, move the pointer over the
icon on the right side of the Logstore, and choose . On the page that appears, you can view the log data in the Logstore.
- Configure search conditions.
For more information, see
Real-time log analysis.
You can modify
Column Settings to specify the columns that are displayed. In the following example, three columns
are displayed: level, msg, and time.

Conclusion
The preceding example demonstrates how to use Log Service to collect the log data
of a serverless Knative application. You can use Log Service to collect and analyze
log data of Knative applications. This helps manage and maintain serverless Knative
applications in a production environment.