tencent cloud

Feedback

Log Description

Last updated: 2022-01-04 16:23:04

    Log Development

    You can use the following statements in the program to output a log:

    • echo or echo()
    • print or print()
    • print_r()
    • var_dump()

    For example, you can query the output content in the function log by running the following code:

    <?php
    function main_handler($event, $context) {
      print_r ($event);
      print_r ($context);
      echo "hello world\n";
      print "hello world\n";
      var_dump ($event);
      return "hello world";
    }
    ?> 
    

    Log Query

    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.

    Note:

    Function logs are delivered to the LogSet log set and LogTopic log topic in CLS, both of which can be queried through the function configuration.

    Custom Log Fields

    Currently, the string content output by simple print or 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.

    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 method

    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:

    <?php
    function main_handler($event, $context) {
      $custom_key = array('key1' => 'test value 1', 'key2' => 'test value 2');
      echo json_encode($custom_key);
      return "hello world";
    }
    ?>
    

    Search method

    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 result
    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