Configure the application log collection policy
If you only need to view real-time logs of certain applications in the cluster and do not want to store these logs (the collector will discard the corresponding logs), you can refer to the solution provided in this section to set the scope of application logs to stop collecting (cluster, namespace, Pod) and achieve fine-grained control of application log collection.
Prerequisites
The log collection component has been deployed in the cluster.
Stop collecting all application logs under the cluster
You can update the Configuration parameter of the log collection component of the cluster to turn off the switch for collecting application logs and uniformly update the log collection scope of the cluster. When the collection switch of a certain type of log is turned off, all logs of this type on the current cluster will stop being collected.
Stop collecting application logs under the specified namespace
By adding the cpaas.io/log.mute=true label to the specified namespace, you can turn off the collection switch for application logs in that namespace and stop collecting standard output logs and file logs of all Pods under that namespace.
The optional configuration methods are as follows:
-
Command line method: After logging in to any control node of the cluster, execute the following command line to update the labels of the namespace.
kubectl label namespace <Namespace Name> cpaas.io/log.mute=true -
Interface Operation: In the Project Management view, update the namespace tag.
-
In the project list of the Project Management view, click on the Project name where the namespace is located.
-
In the left navigation bar, click on Namespaces > Namespaces.
-
Click on the Namespace Name to be updated.
-
On the Details tab, click on the
icon on the right of Tags. -
After adding a tag (key:
cpaas.io/log.mute, value:true) or modifying the value of an existing tag, click on Update.
-
Pod log collection was stopped
By adding the cpaas.io/log.mute=true tag to a specified Pod, the log collection switch of the Pod can be turned off, and the standard output logs and file logs of the Pod will no longer be collected.
After logging in to any control node of the cluster, execute the following command line to update the Pod’s tag.
kubectl label pod <Pod Name> -n <Namespace Name> cpaas.io/log.mute=trueNote: If the Pod belongs to a Workload, you can update the labels of all Pods under the Workload by updating the labels of the Workload (Deployments, StatefulSets, DaemonSets, Jobs, CronJobs) and the labels will not be lost when the Pods are rebuilt.
You can update the labels of a Workload in the following way:
-
In the Container Platform product view, click on the top navigation bar to switch to the namespace where the Pod is located.
-
In the left navigation bar, click on Workloads > Type of the computing component that the Pod belongs to.
-
Click on the
> Update button on the right side of the computing component with the labels to be updated. -
Click on YAML in the upper right corner to switch to the YAML editing view.
-
Under the spec.template.labels field, add the label
cpaas.io/log.mute: 'true'.Example:
spec: template: metadata: namespace: tuhao-test creationTimestamp: null labels: app: spilo cpaas.io/log.mute: 'true' cluster-name: acid-minimal-cluster role: exporter middleware.instance/name: acid-minimal-cluster middleware.instance/type: PostgreSQL -
Click on Update.