You can use the following statements in the program to output a log:
For example, you can query the output content in the function log by running the following code:
Currently, all function logs are delivered to CLS. You can configure the function log delivery. For more information, see Log Delivery Configuration.
You can query function execution logs on the log query page of SCF or CLS. For more information on the log query method, see Log Search Guide.
Function logs are delivered to the
LogSetlog set and
LogTopiclog topic in CLS, both of which can be queried through the function configuration.
Currently, the string content output by simple
logger in the function code will be recorded in the
SCF_Message field when it is delivered to CLS. For descriptions of CLS fields, see Log Delivery Configuration.
At present, SCF supports adding custom fields to the content output to CLS. By doing so, you can output business fields and related data content to logs and use the search capability of CLS to query and track them in the execution process.
- If you need to query the key value of a custom field such as
SCF_CustomKey: SCF, add a key-value index to the log topic for SCF log delivery as instructed in Configuring Indexes.
- To avoid function log query failures caused by misuse of the index configuration, the default destination topic for SCF log delivery (prefixed with
SCF_LogTopic_) does not support modifying the index configuration. You need to set the destination topic to custom delivery first and then update the log topic's index configuration.
- After the index configuration is modified for a log topic, it will take effect only for newly written data.
If a single-line log output by a function is in JSON format, the JSON content will be parsed into the format of
field:value when it is delivered to CLS. Only the first level of the JSON content can be parsed in this way, while other nested structures will be recorded as values.
You can run the following code to test:
After using the above code to perform a test, you can run the following statement to search in Function Management > Log Query > Advanced Search:
After the test is written to CLS, you can find the
key1 field in the log query as shown below: