tencent cloud

Feedback

Log Description

Last updated: 2024-12-02 18:12:22

    Logging

    You can use the following statements in the program to output the log:
    console.log()
    console._stdout.write() (supported for Node.js 8.9 or later)
    process.stdout.write() (supported for Node.js 8.9 or later)
    For example, you can query the output in the function log by running the following code.
    'use strict';
    exports.main_handler = async (event, context) => {
    console.log("Hello World")
    console._stdout.write("Hello World")
    process.stdout.write("Hello World")
    return event
    };

    Notes

    The Node.js 12.16 and 10.15 runtime environments use console.log to print logs. The platform will encapsulate the log content in the format of "timestamp RerquestId log content" and write it to CLS. Example: Log print statement: console.log("hello world") Log output: 2021-12-27T03:53:59.192Z a7358cce-489a-4674-8e4e-68665fa2b81d Hello World
    The Node.js 8.9 runtime environment uses console.log, console._stdout.write(), or process.stdout.write() to print logs. The platform will encapsulate the log content in the format of "timestamp RerquestId log content" and write it to CLS. Example: Log print statement: console.log("hello world") Log output: 2021-12-27T03:53:59.192Z a7358cce-489a-4674-8e4e-68665fa2b81d Hello World
    The Node.js 6.10 runtime environment uses console.log to print logs. The platform will encapsulate the log content in the format of "timestamp RerquestId log content" and write it to CLS. Example: Log print statement: console.log("hello world") Log output: 2021-12-27T03:53:59.192Z a7358cce-489a-4674-8e4e-68665fa2b81d Hello World

    Log Query

    Currently, the function logs can be uploaded to Tencent Cloud SCF. You can complete the configuration as instructed in Log Delivery Configuration. You can search function execution logs on the log query page of the SCF or CLS console. For more information on how to query logs, see Log Search Guide.
    Note:
    Function logs uploaded to logset and log topic can be both queried with a function configured.

    Custom Log Fields

    Currently, the content output by simple log print statements 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.
    Currently, SCF supports adding custom fields to logs that are uploaded to CLS. The custom fields allow you to output business fields and relevant data to logs, and track them using the log search feature of CLS.
    Note:
    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.

    Output

    If a function outputs a single-line log in JSON, the log will be parsed and uploaded to CLS in the field:value format. Only the first layer will be parsed, and the remaining nested structure will be recorded as values.
    Run the following codes and check results:
    'use strict';
    exports.main_handler = async (event, context) => {
    console._stdout.write(JSON.stringify({"key1": "test value 1","key2": "test value 2"})+'\\n');
    return "hello world"
    };
    After using the above code to perform a test, you can run the following statement to search in Function Management > Log Query > Advanced Search:
    
    
    Search for logs After the test is written to CLS, you can find the key1 field in the log query as shown below:
    
    
    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support