The multi-line mode simplifies log collection by treating each log as a single entry within Simple Log Service, without parsing the content of each log. This topic explains how to create a Logtail configuration for multi-line log collection using the Simple Log Service console.
Solution overview
In multi-line mode, Logtail matches the start of a log line using a regular expression. Any unmatched portion is appended to the log. Logs are stored in the content
field without extracting additional fields. The log's timestamp corresponds to the system time at the moment of collection, which is the server time when Logtail is installed.
Consider the following original log:
2024-08-19 13:47:37,070 ERROR Failed to join the cluster, retry...
java.lang.IllegalStateException: Fail to get leader of group naming_service_metadata, Unknown leader
at com.alipay.sofa.jraft.core.CliServiceImpl.getPeers(CliServiceImpl.java:605)
at com.alipay.sofa.jraft.core.CliServiceImpl.getPeers(CliServiceImpl.java:498)
at com.alibaba.nacos.core.distributed.raft.JRaftServer.registerSelfToCluster(JRaftServer.java:353)
at com.alibaba.nacos.core.distributed.raft.JRaftServer.lambda$createMultiRaftGroup$0(JRaftServer.java:264)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
After using multi-line mode for collection into Simple Log Service, the result is as follows:
Prerequisites
A machine group has been created, and servers have been added to the machine group. We recommend that you create a custom identifier-based machine group. For more information, see Create a custom identifier-based machine group or Create an IP address-based machine group.
Ports 80 and 443 are enabled for the server on which Logtail is installed. If the server is an Elastic Computing Service (ECS) instance, you can reconfigure the related security group rules to enable the ports. For more information about how to configure a security group rule, see Add a security group rule.
The server from which you want to collect logs continuously generates logs. Logtail collects only incremental logs. If a log file on your server is not updated after a Logtail configuration is delivered and applied to the server, Logtail does not collect logs from the file. For more information, see Read log files.
1. Select a project and a logstore
Log on to the Simple Log Service console.
Click Quick Data Import on the right side of the console.
On the Import Data page, click Multi-line - Text Logs.
Select the project and logstore you want.
2. Configure a machine group
Apply the Logtail configuration to the specified machine group to collect data from the server. Choose the appropriate scenario and installation environment based on your requirements, because this will influence subsequent configurations.
Existing machine group
Select the desired machine group from the Source Machine Group list and click Next.
No available machine group
Click Create Machine Group and configure the parameters in the Create Machine Group panel. Machine group identities are categorized as either IP Address or Custom Identifier. For more information, see Create a custom identifier-based machine group and Create an IP address-based machine group.
ImportantIf the machine group is applied immediately after creation, the heartbeat may show a status of FAIL due to an ineffective connection. Click Retry. If the problem persists, see How do I troubleshoot an error related to a Logtail machine group in a host environment?
3. Configure a Logtail
3.1 Global configurations
3.2 Input configurations
3.3 Processor configurations
Log Sample: Supports multiple logs. Log samples can help configure log processing parameters, facilitating the setup process. We recommend that you add log samples.
Multi-line Mode: Enabled to collect multi-line logs.
Type: Select Custom. For example, the regular expression to match the beginning of a line is
\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2},\d+\s.*
.Processing Method If Splitting Fails: Select Keep Single Line.
Processing Method: Select None.
A Logtail configuration requires up to three minutes to take effect.
4. Query and analysis configurations
By default, Simple Log Service enables full-text indexing. You can also manually create field indexes, or click Automatic Index Generation to automatically generate indexes. For more information, see Create indexes.
5. Query logs
Click Query Log to go to the query and analysis page.
Wait approximately one minute for the index to activate before viewing the collected logs on the Raw Logs tab. For more information, see Query and analyze logs.
To query all fields in logs, use full-text indexes. To query only specific fields, use field indexes, which helps reduce index traffic. To perform field analysis, create field indexes and include a SELECT statement in your analysis query.
What to do next
For more information about log index types, configuration examples, and index-related billing, see Create indexes.
For more information about log query syntax, see Search syntax.