You need to enable JavaScript to run this app.
Torch Log Service

Torch Log Service

Copy page
Download PDF
Global operation function
Flow control function
Copy page
Download PDF
Flow control function
This topic describes the syntax and format of flow control functions, along with relevant scenario examples.​
c_if function​
This function processes logs that meet certain conditions. If no condition is met, no actions will be taken.​
  • The conditions and actions in the function parameters must appear in pairs, and there must be at least one pair of condition and action combination.​
  • If there are multiple true conditions, only the action for the first true condition is executed.​
Function syntax/format​
​
c_if(condition 1, action 1, condition 2, action 2, ……)​
​
The parameters are described below:​
​
Parameters​
Parameter type​
Required​
Default value​
Value range​
Description​
Condition​
Any​
Yes​
/​
/​
Expression or a combination of expressions. If they are not Boolean types, they will be converted to Boolean types before evaluation.​
Actions​
Global operation function​
Yes​
/​
/​
Global operation function or combinations.​
​
Function examples​
  • Scenario: When the original log contains the phone field, newly add the contact_type field.​
  • Processing rules:​
  • ​
    c_if(f_has("phone"), f_set("contact_type", "telephone"))​
    ​
  • Log example​
  • ​
    [​
    {​
    "user_name":"Smith",​
    "phone":"135xxxx5678"​
    },​
    {​
    "user_name":"Paul",​
    "city":"chengdu"​
    }​
    ]​
    ​
  • Processing result:​
  • ​
    [​
    {​
    "user_name":"Smith",​
    "phone":"135xxxx5678",​
    "contact_type":"telephone"​
    },​
    {​
    "user_name":"Paul",​
    "city":"chengdu"​
    }​
    ]​
    ​
Tip​
The first log contains the phone field and adds the contact_type field after processing. The second log does not contain the phone field, so the phone field is not added after processing.​
c_if_else function​
Process different logic based on condition evaluation. If the condition is true, perform action 1; otherwise, perform action 2.​
Function syntax/format​
​
c_if_else(condition, action 1, action 2)​
​
The parameters are described below:​
​
Parameters​
Parameter type​
Required​
Default value​
Value range​
Description​
Condition​
Any​
Yes​
/​
/​
Expression or a combination of expressions. If they are not Boolean types, they will be converted to Boolean types before evaluation.​
Operation 1​
Global operation function​
Yes​
/​
/​
Global operation function or combinations.​
Operation 2​
Global operation function​
Yes​
/​
/​
Global operation function or combinations.​
​
Function examples​
  • Scenario: Determine whether a person is an adult based on the age field, and output the result to a new field is_adult.​
  • Processing rules:​
  • ​
    c_if_else(op_ge(v("age"), 18), f_set("is_adult", True), f_set("is_adult", False))​
    ​
  • Log example​
  • ​
    [​
    {​
    "name":"Agatha",​
    "age":"20"​
    },​
    {​
    "name":"Elvin",​
    "age":"17"​
    }​
    ]​
    ​
  • Processing result:​
  • ​
    [​
    {​
    "name":"Agatha",​
    "age":"20",​
    "is_adult":true​
    },​
    {​
    "name":"Elvin",​
    "age":"17",​
    "is_adult":false​
    }​
    ]​
    ​
c_switch function​
Process different logic based on condition evaluation. Based on multiple branch conditions, execute the action corresponding to the first true condition. If none of the conditions are met, the default action will be executed.​
Function syntax/format​
​
c_switch(condition 1, action 1, condition 2, action 2, ..., default=default action )​
​
The parameters are described below:​
​
Parameters​
Parameter type​
Required​
Default value​
Value range​
Description​
Condition​
Any​
Yes​
/​
/​
Expression or a combination of expressions. If they are not Boolean types, they will be converted to Boolean types before evaluation.​
Actions​
Global operation function​
Yes​
/​
/​
Global operation function or combinations.​
default​
Global operation function​
Yes​
/​
/​
Default operation, global operation function or combinations thereof.​
​
Function examples​
  • Scenario: Determine the region based on the city log field.​
  • Processing rules:​
  • ​
    c_switch(op_eq(v("city"), "chengdu"), f_set("region", "West"), op_eq(v("city"), "shanghai"), f_set("region", "East"))​
    ​
  • Log example​
  • ​
    [​
    {​
    "name":"Agatha",​
    "city":"chengdu"​
    },​
    {​
    "name":"Elvin",​
    "city":"shanghai"​
    }​
    ]​
    ​
  • Processing result:​
  • ​
    [​
    {​
    "name":"Agatha",​
    "city":"chengdu",​
    "region":"West"​
    },​
    {​
    "name":"Elvin",​
    "city":"shanghai",​
    "region":"East"​
    }​
    ]​
    ​
c_compose function​
Used to combine multiple operations. All operations should be global operation functions.​
  • TLS will sequentially invoke the specified operations, transmitting, transforming, and finally returning the log data.​
  • For a given log record, if any global operation deletes the log, TLS will not execute subsequent operations on it.​
Function syntax/format​
​
c_compose(action 1, action 2...)​
​
The parameters are described below:​
​
Parameters​
Parameter type​
Required​
Default value​
Value range​
Description​
Actions​
Global operation function​
Yes​
/​
/​
Multiple global operation functions or combinations thereof.​
​
Function examples​
  • Scenario: When the log contains a content field, update its value to value1 and rename it to content_modified.​
  • Processing rules:​
  • ​
    c_if(f_has("content"),c_compose(f_set("content","value1"),f_rename("content","content_modified")))​
    ​
  • Log example​
  • ​
    {​
    "content":"value"​
    }​
    ​
  • Processing result:​
  • ​
    {​
    "content_modified":"value1"​
    }​
    ​
​
Last updated: 2026.05.08 16:28:57