LogCollector collects text logs from servers according to the collection configuration and supports parsing JSON logs using JSON mode. In JSON mode, LogCollector extracts key-value pairs from JSON logs. This topic describes how to create a JSON mode collection configuration.
Background information
Torch log service (TLS) LogCollector supports collecting and parsing Object-type JSON logs. During parsing, it extracts the first-layer keys from the Object as field names and their corresponding first-layer values as field values based on the JSON format. Each complete log ends with a line break symbol \n.
In JSON mode, TLS adds the following metadata fields to the log data that is collected by LogCollector and creates indexes for them by default.
Prerequisites
- The server where LogCollector is installed must be able to access port 80 and port 443 on the remote server.
Steps
Step 1 Select a log space
- Select the region where torch log service is located from the top navigation bar.
- On the left navigation bar, select Common functions > Log Collection.
- Then on the Log Collection page, in the LogCollector tab, click Create collection configuration.
Notice
For the regions below, manually select the log collection mode in the LogCollector tab.
Region: Hong Kong (China), Asia Pacific Southeast (Johor), Asia Pacific Southeast (Jakarta).
- Select project and topic, and then click Next: Select host group.
- The collected log data will be stored in the selected log topic.
Step 2 Select host group
- In the All host groups section, select the specified host group for log collection.
- After confirming the host group in the Selected host group section, click Next Step: Collection rule.
Step 3 Configure collection rule
Configure basic information
- Rule name refers to the name of the LogCollector collection configuration.
- You can also click Import collection rules, and select Source region, Source project, and Source configuration rule to import existing collection configurations into the current one. You only need to specify the collection rule name.
- Select whether to enable Container log collection.
- By default, the container log collection is disabled. If you collect host group logs or collect container logs via Sidecar, keep this setting disabled.
- Enter the Collection path.
- Collection path refers to the directory and filename of the logs. LogCollector matches directories based on the directory part of the collection path and monitors log files in those directories that meet the rules. You can set up to 10 different collection paths.
- You can specify a complete directory and filename for collection path. Besides, collection path supports fuzzy matching via wildcard character.
Notice
- By default, a log file can only match one collection configuration and is collected into one log topic. If multiple collection configurations collect the same file, the latest created collection configuration rule applies.
- When the wildcard ** is specified in the log collection path, the path matches multiple directory levels. In this case and only in this case, TLS monitors subdirectories up to 8 levels deep under the specified directory.
- TLS currently supports the following wildcards: asterisk *, double asterisk **, and question mark ?. Only one double asterisk ** can be configured at most.
- Common configuration methods and examples for collection paths are as follows.
- Set collection configuration effectiveness policy.
- When log files under the same collection path are matched by multiple collection configurations, the following policies can be set:
- Set collection path denylist.
- After configuring the collection path denylist, TLS skips the specified directories and files when collecting logs through LogCollector. After selecting Enable, set the denylist directories and files as prompted on the page.
Notice
- Each collection configuration can set up to 10 denylist collection paths.
- When configuring log paths, if you use wildcards but need to exclude certain directories or files, you need to enter the corresponding full paths or filenames in the denylist to ensure effective filtering. For example, if the collection path is /var/log/project/*.log and you want to exclude all subdirectories under /var/log/project, then the collection path denylist should be set to directory paths, with the configured path /var/log/project/**.
The path types in the collection path denylist support setting as directory path and file path.
- Set the Collection policy.
- The collection policy determines whether LogCollector collects incremental logs or complete logs. By default, it collects increment logs.
Notice
If the Increment collection policy is selected, after triggering LogCollector collection, the collection policy can not switch to Full collection policy to collect historical logs of the log.
- Collection mode refers to the LogCollector's log file parsing mode. In this case, set this to JSON mode.
- Manual setup: Click JSON.
- Automatic setup: Click AI-recommended collection mode, and then enter or upload log samples. TLS will use TLS Copilot to analyze your log samples automatically. After analysis, you can complete relevant configurations in one click as prompted. The recommended result is for reference only; you need to verify based on your actual needs.
Notice
- You must read and agree to the disclaimer and terms of service before using TLS Copilot for the first time.
- TLS Copilot is available only in North China 2 (Beijing), South China 1 (Guangzhou), and East China 2 (Shanghai).
In JSON mode, the newline character (\n) marks the end of a log entry. The top-level keys in the object serve as field names, and the top-level values serve as field values.
- Acquisition point in time: use the system time of the server where LogCollector runs as the log timestamp.
- Custom time: extract the time embedded in the original log as the log timestamp. The related configuration is as follows:
- Select whether to skip files that have not been updated.
- If enabled, LogCollector skips files whose log file update time falls outside your specified time range when collecting data.
- Set whether to enable upload parsing failure log.
- Enable: After enabling, you must also configure the failure log key name. The key name defaults to LogParseFailed. All logs that fail to parse are uploaded to TLS, using the configured failure log key name field as the key and the original log content as the value.
- Disable: Logs that fail to parse are not uploaded to TLS.
Choose whether to enable Plugin configuration.
When collecting text logs via LogCollector, if business logs can not be parsed by regular collection modes like JSON due to complex structures or inconsistent format, use LogCollector plugin for post-collection processing. For more details, see Plugin overview. - Enable Advanced settings.
Select advanced configurations based on your needs. If you have no special requirements, we recommend that you keep the default configuration.
- Confirm the collection configuration and click Next step: Check index configuration.
Step 4 Check index configuration
- Check index configuration.
- Follow the prompts on the page to set or update the index as needed. You can also click Import existing index configuration to import indexes from other log topics.
- If the index for this log topic is already configured, you can decide whether to update the index based on the log fields parsed by the collection rule.
Notice
- You must enable the index to query and analyze the collected log data.
- The updated index settings only apply to new data written afterward. For more instructions and limitations on query and analysis, see Query overview and Analysis Overview.
Next steps
After you create the collection configuration, LogCollector collects logs and saves them to the specified log topic. You can then query and analyze logs in log topic. For specific instructions, see Query and analysis workflow.