A single-line full-text log refers to a log where each line represents a complete log entry. When collecting logs, CLS uses the line break \\n as the delimiter to mark the end of each log entry. For unified structured management, each log will have a default key-value pair __CONTENT__. However, the log data itself will not be processed in a structured manner, nor will log fields be extracted. The time attribute of a log is determined by the time when the log is collected.
Assume that the raw data of a log is:
Tue Jan 22 12:08:15 CST 2019 Installed: libjpeg-turbo-static-1.2.90-6.el7.x86_64
The data collected into CLS is:
__CONTENT__:Tue Jan 22 12:08:15 CST 2019 Installed: libjpeg-turbo-static-1.2.90-6.el7.x86_64
The single-line full regular expression format is usually used to process structured logs. This represents a log parsing mode in which multiple key-value pairs are extracted from a complete log entry using regular expressions.
Assume that the raw data of a log is:
10.135.46.111 - - [22/Jan/2019:19:19:30 +0800] "GET /my/course/1 HTTP/1.1" 127.0.0.1 200 782 9703 "http://127.0.0.1/course/explore?filter%5Btype%5D=all&filter%5Bprice%5D=all&filter%5BcurrentLevelId%5D=all&orderBy=studentNum" "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:64.0) Gecko/20100101 Firefox/64.0" 0.354 0.354
The configured regular expression is as follows:
(\\S+)[^\\[]+(\\[[^:]+:\\d+:\\d+:\\d+\\s\\S+)\\s"(\\w+)\\s(\\S+)\\s([^"]+)"\\s(\\S+)\\s(\\d+)\\s(\\d+)\\s(\\d+)\\s"([^"]+)"\\s"([^"]+)"\\s+(\\S+)\\s(\\S+).*
The data collected into CLS is:
ody_bytes_sent: 9703
http_host: 127.0.0.1
http_protocol: HTTP/1.1
http_referer: http://127.0.0.1/course/explore?filter%5Btype%5D=all&filter%5Bprice%5D=all&filter%5BcurrentLevelId%5D=all&orderBy=studentNum
http_user_agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:64.0) Gecko/20100101 Firefox/64.0
remote_addr: 10.135.46.111
request_length: 782
request_method: GET
request_time: 0.354
request_url: /my/course/1
status: 200
time_local: [22/Jan/2019:19:19:30 +0800]
upstream_response_time: 0.354
Single-Line Full Regular Expression Mode:
1. On the Collection Configuration page, set "Extraction Mode" to Single-Line Full Regular Expression and enter a log sample in the "Log Sample" text box. As shown below:
2. Define the regular expression according to the following rules:
The system provides two modes, Manual Mode and Auto Mode, for defining regular expressions. Based on the mode you select and the defined regular expression, the system extracts key-value pairs to verify the regular expression.
You can manually enter an expression to extract key-value pairs for verification.
(1) In the text box of Regular Expression, enter a regular expression.
(2) Click Verify and the system will judge whether the log sample matches the regular expression.
You can click Auto Regular Expression Tool to switch to Auto Mode:
(1) In the pop-up "Regular Expression Auto-Generation
" modal view, based on your actual search and analysis needs, left-click to select the log content from which you need to extract key-value pairs. Then, in the pop-up text box, enter the key name and click Confirm Extraction. As shown below: The system will automatically generate a regular expression for this part of the content. The automatic extraction result will appear in the key-value table on the right, and the extraction regular expression automatically generated based on the automatic extraction result will appear in the table below. As shown below:
(3) Click OK. The system will automatically generate a complete regular expression based on the extracted key-value pairs.
Note:
Regardless of whether you use Manual Mode or Auto Mode, after the definition is completed and verified, the extraction results will be displayed in the "Log Extraction Results" section. If the results do not meet your expectations, you can return to Define Regular Expression to edit it again and re-verify. You only need to define the key name for each key-value pair, and then you can use that name for log search and analysis.
More Log Verification:
1. When you have multiple complex log sample data, you can set Match More Logs to to verify the pass rate of your regular expression sample. 2. Enter the log samples to be verified, separating multiple data entries with line breaks. Click Verify, and the system will verify the sample pass rate. When appears, it indicates that the verification has passed, as shown below: Multi-line full-text logs refer to complete log entries that may span multiple lines (such as Java stack traces). In such cases, to enable the logging system to clearly distinguish between log entries, a first-line regular expression matching method is adopted. When a log line matches the predefined regular expression, it is identified as the start of a log entry, and the appearance of the next matching first line serves as the end marker for that log entry.
A multi-line full-text log will also have a default key-value pair __CONTENT__. However, the log data itself will not be processed in a structured manner, nor will log fields be extracted. The time attribute of a log is determined by the time when the log is collected.
Assume that the raw data of a multi-line log is:
2019-12-15 17:13:06,043 [main] ERROR com.test.logging.FooFactory:
java.lang.NullPointerException
at com.test.logging.FooFactory.createFoo(FooFactory.java:15)
at com.test.logging.FooFactoryTest.test(FooFactoryTest.java:11)
The first-line regular expression is as follows:
\\d{4}-\\d{2}-\\d{2}\\s\\d{2}:\\d{2}:\\d{2},\\d{3}\\s.+
The data collected into CLS is:
__CONTENT__:2019-12-15 17:13:06,043 [main] ERROR com.test.logging.FooFactory:\\njava.lang.NullPointerException\\n at com.test.logging.FooFactory.createFoo(FooFactory.java:15)\\n at com.test.logging.FooFactoryTest.test(FooFactoryTest.java:11)
Configure Multi-Line Full-Text Format:
1. On the "Collection Configuration" page, set the "Extraction Pattern" to Multiple lines - full-text log. As shown below:
2. Define the regular expression according to the following rules.
3. You can define the first-line regular expression using either the Auto-Generate or Manual Input method. The system will then verify the regular expression based on the sample content.
Auto-Generate: Enter a log sample in the text box and click Auto-Generate. The system will automatically generate a first-line regular expression in the grayed-out text box.
Enter Manually: Enter a log sample in the text box, enter the first-line regular expression, and click Verify. The system will check whether the expression passes verification.
Configure Upload of Parsing-Failure Logs:
It is recommended to enable the upload of logs that failed to be parsed. After this feature is enabled, LogListener will upload various logs that failed to be parsed. If this feature is disabled, the logs that failed to be parsed will be discarded.
After this feature is enabled, you need to configure the key value for parsing failures (which is LogParseFailure by default). All logs that failed to be parsed are uploaded with the input content as the key name (Key) and the raw log content as the key value (Value).
Assume that the raw data of a log is:
[2018-10-01T10:30:01,000] [INFO] java.lang.Exception: exception happened
at TestPrintStackTrace.f(TestPrintStackTrace.java:3)
at TestPrintStackTrace.g(TestPrintStackTrace.java:7)
at TestPrintStackTrace.main(TestPrintStackTrace.java:16)
The first-line regular expression is:
\\[\\d+-\\d+-\\w+:\\d+:\\d+,\\d+]\\s\\[\\w+]\\s.*
The configured custom regular expression is:
\\[(\\d+-\\d+-\\w+:\\d+:\\d+,\\d+)\\]\\s\\[(\\w+)\\]\\s(.*)
After the system extracts the corresponding key-value pair based on the () capture group, you can customize the key name of each group as follows:
time: 2018-10-01T10:30:01,000`
level: INFO`
msg:java.lang.Exception: exception happened
at TestPrintStackTrace.f(TestPrintStackTrace.java:3)
at TestPrintStackTrace.g(TestPrintStackTrace.java:7)
at TestPrintStackTrace.main(TestPrintStackTrace.java:16)
Multi-Line Full Regular Expression Mode
1. On the collection configuration page, set "Extraction mode" to Multi-line Full regular expression, and enter a log sample in the "Log example" textbox. As shown below:
2. Define the first-line regular expression according to the following rules:
3. You can choose whether to enable the Auto-Generate method to define first-line regular expression (disable it to manually enter), and determine cross-line log boundary. After the expression is verified successfully, the system will determine the number of logs that match the first-line regular expression.
Auto generate: Turn on Auto-Generate, and the system automatically generates the first-line regular expression in the grayed-out text box. As shown below:
Enter manually: In the text box, manually enter the first-line regular expression, click Verify, and the system will determine whether the expression passes verification. As shown below:
Extract Regular Expression
The system provides two modes to define regular expressions: manual mode and auto mode. You can either manually enter the expression to extract key-value pairs for verification, or click Auto-Generate Regular Expression to switch to automatic mode. The system will extract key-value pairs based on the selected mode and the defined regular expression for verification.
1. Enter the regular expression in the Extract Regular Expression text box.
2. Click Verify and the system will determine whether the log sample matches the regular expression.
1. In the pop-up "Regular Expression Auto-Generation
" modal view, based on your actual search and analysis needs, select the log content from which you need to extract key-value pairs. Then, in the pop-up text box, enter the key name and click Confirm Extraction. As shown below: 2. The system will automatically generate a regular expression for this part of the content, and the automatic extraction result will appear in the key-value table. As shown below:
4. Click OK. The system will automatically generate a complete regular expression based on the extracted key-value pairs. As shown below:
Note:
Whether you choose automatic mode or manual mode, after the regular expression extraction mode is defined and verified, the extraction results will be displayed in the Extraction Results section. You only need to define the key name for each key-value pair, which can then be used for log search and analysis.
Match More Logs:
1. When your log data is complex, you can set Match More Logs to to verify the pass rate of your regular expression sample. 2. Enter multiple log samples to be verified and click Verify. The system will then verify the sample pass rate. When appears, it indicates that the verification has passed, as shown below: Configure Log Timestamp Source:
You can choose either log collection time or a specified log field as the timestamp for the logs:
Use the log collection time as the log timestamp.
Use the value from a specified field in the log as the log timestamp.
Select the extracted Value from the Log Time Gield as the log time.
In Time Parsing Format, manually enter or select the corresponding parsing expression. For example: the value representing time in logs is 07/Jul/2025:19:19:30 +0800, and the parsing format is %d/%b/%Y:%H:%M:%S %z. For more information, please refer to configure time format. Click Verify.
Note:
If the time format is entered incorrectly, the log timestamp will be based on the collection time.
Configure Upload of Parsing-Failure Logs:
It is recommended to enable the upload of logs that failed to be parsed. After this feature is enabled, LogListener will upload various logs that failed to be parsed. If this feature is disabled, the logs that failed to be parsed will be discarded.
After this feature is enabled, you need to configure the key value for parsing failures (which is LogParseFailure by default). All logs that failed to be parsed are uploaded with the input content as the key name (Key) and the raw log content as the key value (Value).
Assume that the raw data of a JSON log is:
{"remote_ip":"10.135.46.111","time_local":"22/Jan/2019:19:19:34 +0800","body_sent":23,"responsetime":0.232,"upstreamtime":"0.232","upstreamhost":"unix:/tmp/php-cgi.sock","http_host":"127.0.0.1","method":"POST","url":"/event/dispatch","request":"POST /event/dispatch HTTP/1.1","xff":"-","referer":"http://127.0.0.1/my/course/4","agent":"Mozilla/5.0 (Windows NT 10.0; WOW64; rv:64.0) Gecko/20100101 Firefox/64.0","response_code":"200"}
After being structured by CLS, the log becomes:
agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:64.0) Gecko/20100101 Firefox/64.0
body_sent: 23
http_host: 127.0.0.1
method: POST
referer: http://127.0.0.1/my/course/4
remote_ip: 10.135.46.111
request: POST /event/dispatch HTTP/1.1
response_code: 200
responsetime: 0.232
time_local: 22/Jan/2019:19:19:34 +0800
upstreamhost: unix:/tmp/php-cgi.sock
upstreamtime: 0.232
url: /event/dispatch
xff: -
Configure Log Timestamp Source:
Use the log collection time as the log timestamp.
Use the value from a specified field in the log as the log timestamp.
In the Log Time field, manually enter the time field specified in the JSON as the log timestamp.
In Time Parsing Format, manually enter or select the corresponding parsing expression. For example: the value representing time in logs is 07/Jul/2025:19:19:30 +0800, and the parsing format is %d/%b/%Y:%H:%M:%S %z. For more information, please refer to configure time format. Click Verify.
Note:
If the time format is entered incorrectly, the log timestamp will be based on the collection time.
Configure Upload of Parsing-Failure Logs:
It is recommended to enable the upload of logs that failed to be parsed. After this feature is enabled, LogListener will upload various logs that failed to be parsed. If this feature is disabled, the logs that failed to be parsed will be discarded.
After this feature is enabled, you need to configure the key value for parsing failures (which is LogParseFailure by default). All logs that failed to be parsed are uploaded with the input content as the key name (Key) and the raw log content as the key value (Value).
Assume that the raw data of a log is:
10.20.20.10 - ::: [Tue Jan 22 14:49:45 CST 2019 +0800] ::: GET /online/sample HTTP/1.1 ::: 127.0.0.1 ::: 200 ::: 647 ::: 35 ::: http://127.0.0.1/
When the delimiter for log parsing is specified as :::, this log will be divided into eight fields, and each of these fields will be assigned a unique key, as shown below:
IP: 10.20.20.10 -
bytes: 35
host: 127.0.0.1
length: 647
referer: http://127.0.0.1/
request: GET /online/sample HTTP/1.1
status: 200
time: [Tue Jan 22 14:49:45 CST 2019 +0800]
Configure Delimiter Mode:
1. Set Extraction Mode to Delimiter.
2. Select Delimiter and enter a log sample in the Log Sample text box, and then click Extract.
The system splits the log sample according to the determined delimiter and displays it in the extraction result panel. Define a unique key for each field. Currently, log collection supports multiple delimiters; common delimiters include: space, tab, comma, semicolon, and vertical bar. If the delimiter used in your log data is another symbol, such as :::, you can also parse it through a custom delimiter.
Configure Log Timestamp Source:
Use the log collection time as the log timestamp.
Use the value from a specified field in the log as the log timestamp.
Select the extracted Value from the Log Time Gield as the log time.
In Time Parsing Format, manually enter or select the corresponding parsing expression. For example: the value representing time in logs is 07/Jul/2025:19:19:30 +0800, and the parsing format is %d/%b/%Y:%H:%M:%S %z. For more information, please refer to configure time format. Click Verify.
Note:
If the time format is entered incorrectly, the log timestamp will be based on the collection time.
Configure Upload of Parsing-Failure Logs:
It is recommended to enable the upload of logs that failed to be parsed. After this feature is enabled, LogListener will upload various logs that failed to be parsed. If this feature is disabled, the logs that failed to be parsed will be discarded.
After this feature is enabled, you need to configure the key value for parsing failures (which is LogParseFailure by default). All logs that failed to be parsed are uploaded with the input content as the key name (Key) and the raw log content as the key value (Value).