${变量名} 引用预设字段变量,例如 ${RequestHost} 。支持的预设字段列表请参见 七层访问日志。变量 | 含义 | 示例 |
${http.request.headers['key']} | 客户端请求指定头部的值 | ${http.request.headers['user-agent']} |
${http.response.headers['key']} | EO 响应给客户端的指定头部的值 | ${http.response.headers['content-type']} |
${http.request.cookie['key']} | 客户端请求 Cookie 中指定字段的值 | ${http.request.cookie['session_id']} |
${http.request.body} | HTTP 请求正文 | ${http.request.body} |
'abc'。数值常量可直接写作 2 或者 0.2 。\\\\、\\'、\\"、\\/、\\b、\\f、\\t、\\uHHHH。类别 | 运算符 | 说明 |
算术运算符 | +、-、*、/ | 前后均需为数值类型。 |
比较运算符 | <、<=、>、>= | 前后均需为数值类型。 |
比较运算符 | ==、!= | 前后均需为数值或同时为字符串。 |
逻辑运算符 | &&、|| | 仅在公式参数内使用(如 if)。 |
公式名 | 用法 | 作用 | 示例(输入表达式) | 示例(输出值) |
concat | concat(String1, String2, ..., StringN) | 将多个值拼接为一个字符串 | concat('Hello, ', 'World', '!') | Hello, World! |
encode_uri | encode_uri(source) | 对 URI 中破坏性字符进行编码(空格、汉字等),保留 :/?.&=# 结构字符 | encode_uri('https://example.com/search?q=hello world') | https://example.com/search?q=hello%20world |
lower | lower(str) | 将字符串转换为小写 | lower('Hello World') | hello world |
upper | upper(str) | 将字符串转换为大写 | upper('Hello World') | HELLO WORLD |
regexp_replace | regexp_replace(source, regex, replacement) | 正则替换 | regexp_replace('Chrome/120.0.0', 'Chrome/[0-9.]+', 'Chrome/<ver>') | Chrome/<ver> |
regexp_extract | regexp_extract(expr, pattern[, index]) | 正则提取。 index 为 0 时返回整个匹配内容,为 1、2、3... 时返回对应序号的捕获组;index 缺省时默认为 0。 | regexp_extract('Chrome/120.0.0', 'Chrome/([0-9.]+)', 1) | 120.0.0 |
if | if(predicate, then, else) | 根据条件判断返回不同值 | if(1 < 2, 'yes', 'no') | yes |
cast | cast(expr, type) | 转换值的类型, type 为 LONG、DOUBLE 或 STRING | cast(200, 'STRING') | 200 |
timestamp_format | timestamp_format(expr[, pattern[, timezone]]) | 将 UNIX epoch 毫秒级时间戳转为指定格式。 pattern 遵循 Joda-Time 格式,如不填则默认为 ISO 8601。timezone 支持 Joda-Time 时区名称(如 Asia/Shanghai)或固定偏移(如 +08:00),缺省时使用 UTC | timestamp_format(1700000000000, 'yyyy-MM-dd HH:mm:ss') | 2023-11-14 22:13:20 |
unix_timestamp | unix_timestamp(timestamp) | 将 ISO 8601 时间字符串转为 UNIX epoch 秒级时间戳 | unix_timestamp('2023-11-14T22:13:20Z') | 1700000000 |
_),必须以字母开头。'a' + ${RequestHost}),请使用 concat() 公式完成拼接。$ 可触发预设变量提示;输入公式名可触发公式快速检索。ClientInfoconcat('host=', ${RequestHost}, ' ip=', ${ClientIP}, ' status=', ${EdgeResponseStatusCode})
"ClientInfo": "host=www.example.com ip=1.2.3.4 status=200"
StatusCategoryif(${EdgeResponseStatusCode}>=200 && ${EdgeResponseStatusCode}<300, 'success', 'error')
>=、< 比较运算符结合 && 逻辑运算符,在 if 公式中实现条件判断。"StatusCategory": "success"
"StatusCategory": "error"
Content-Type。ContentType${http.response.headers['content-type']}
"ContentType": "text/html; charset=utf-8"
ChromeVersionregexp_extract(${http.request.headers['user-agent']}, 'Chrome/([0-9.]+)', 1)
regexp_extract 公式的第三个参数为捕获组序号,1 表示提取第一个捕获组 ([0-9.]+) 的内容。"ChromeVersion": "120.0.0"
RequestTimeFormattedtimestamp_format(unix_timestamp(${RequestTime})*1000, 'yyyy-MM-dd HH:mm:ss', 'Asia/Shanghai')
${RequestTime} 为 ISO 8601 格式字符串,通过 unix_timestamp() 转为秒级时间戳后乘以 1000 得到毫秒值,再由 timestamp_format() 格式化输出。第三个参数 'Asia/Shanghai' 指定输出时区为北京时间,缺省时使用 UTC。"RequestTimeFormatted": "2025-08-06 14:30:00"
<custom_field_value> ::= <expr><expr> ::= <term> ("+" | "-" <term>)*<term> ::= <factor> ("*" | "/" | "%" <factor>)*<factor> ::= ("-")? <primary><primary> ::= <num> | <literal_string> | <var> | <func_call> | "(" <expr> ")"<var> ::= "$" "{" <var_name> (<index_key>)? "}"<var_name> ::= [a-zA-Z] ([a-zA-Z0-9] | "_" | ".")*<index_key> ::= "[" <literal_string> "]"<func_call> ::= <func_name> "(" (<func_args>)? ")"<func_name> ::= [a-z] ([a-z] | [0-9] | "_")*<func_args> ::= <func_arg> ("," <func_arg>)*<func_arg> ::= <logic_or><logic_or> ::= <logic_and> ("||" <logic_and>)*<logic_and> ::= <comparison> ("&&" <comparison>)*<comparison> ::= <expr> (<cmp_op> <expr>)?<cmp_op> ::= "==" | "!=" | ">=" | "<=" | ">" | "<"<num> ::= [0-9]+ ("." [0-9]+)?<literal_string> ::= "'" (<ls_plain> | <ls_escape>)* "'"<ls_escape> ::= "\\" ("'" | """ | "\\" | "/" | "b" | "f" | "t" | <unicode_esc>)<unicode_esc> ::= "u" <hex> <hex> <hex> <hex><hex> ::= [0-9] | [a-f] | [A-F]<ls_plain> ::= [a-zA-Z0-9] | " " | "!" | """ | "#" | "$" | "%" | "&" | "("| ")" | "*" | "+" | "," | "-" | "." | "/" | ":" | ";" | "<"| "=" | ">" | "?" | "@" | "[" | "]" | "^" | "_" | "`"| "{" | "|" | "}" | "~"
文档反馈