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

Torch Log Service

Copy page
Download PDF
LogCollector plugins
Time parsing plugin
Copy page
Download PDF
Time parsing plugin
When you collect logs with LogCollector, you can use the strp_time time parsing plugin to parse time information from raw logs. The parsed time is then recorded on the server as the log timestamp.​
Description​
This plugin is supported in LogCollector V1.0.48 and later versions. To view the LogCollector version, see 2. View software version.​
Parameters description​
​
Name​
Type​
Required​
Description​
field​
String​
Yes​
Name of the field to be parsed.​
format​
String​
Yes​
Specify the time format for parsing time values. For details on time formats, see Time format.​
  • By default, when configuring the time conversion format, millisecond-level settings are supported. If time conversion format does not specify millisecond parsing, the millisecond part defaults to 0.​
  • When you enable the high-precision timestamp feature, you can configure the time conversion format to nanosecond precision. If the time conversion format does not specify how to parse nanoseconds, the nanosecond part will automatically be set to 0.​
time_zone​
String​
No​
Configure the time zone. The default time zone is the same as the server where LogCollector is located, and both GMT and UTC are supported.​
For example: GMT+08:00, Asia/Shanghai.​
extract_regex​
String​
No​
Regular expression for extracting time.​
If you only need to parse part of the time from a field, you can use a regular expression to extract it.​
enable_nanosecond​
Boolean​
No​
This parameter determines whether to enable high-precision time.​
When enabled, the parsed log time is accurate to nanosecond. By default, log time has millisecond precision.​
set_year​
String​
No​
If the log timestamp is missing the year information, you can add the year information to the log time via this parameter.​
  • You can set a specific fixed year, for example "set_year": "2024".​
  • Use the current system year, for example "set_year": "auto".​
  • If you set "set_year": "auto" and configure time_zone, the system will convert the time based on your time_zone setting before obtaining the year.​
  • For example, if the current system time is London time 2023-12-31 20:00:00 and time_zone is GMT+08:00, the time will be converted to Beijing time 2024-01-01 04:00:00, and 2024 will be used as the year.​
  • When "set_year": "auto" is set, a slight delay in data collection across the new year may cause incorrect year information. Therefore, we recommend that you print the year information in the log timestamp.​
​
Configuration examples​
Example 1: Disable high-precision timestamp​
  • Key-value logs processed by collection mode or other plugins.​
  • ​
    {"message": "[2023-12-19T19:00:00,000] [INFO] java.lang.Exception: exception happened"}​
    ​
  • Plugin configuration for LogCollector​
  • ​
    {​
    "processors": [​
    {​
    "strp_time": {​
    "field": "message",​
    "format": "%Y-%m-%dT%H:%M:%S,%f",​
    "time_zone": "GMT+08:00",​
    "extract_regex": "\\[(\\d{4}\\-\\d{2}\\-\\d{2}T\\d{2}:\\d{2}:\\d{2},\\d{3})\\]"​
    }​
    }​
    ]​
    }​
    ​
  • Processing result​
  • The parsed log timestamp is 1702983600000, which is 2023-12-19 19:00:00,000.​
  • ​
    "message": "[2023-12-19T19:00:00,000] [INFO] java.lang.Exception: exception happened"​
    Log.Time=1702983600000​
    ​
Example 2: Enable high-precision timestamp​
  • Key-value pair logs processed by collection mode or other plugins.​
  • ​
    {"message": "[2024-05-15T12:30:19,123456789] [INFO] java.lang.Exception: exception happened"}​
    ​
  • Plugin configuration for LogCollector​
  • ​
    {​
    "processors": [​
    {​
    "strp_time": {​
    "field": "message",​
    "format": "%Y-%m-%dT%H:%M:%S,%f",​
    "time_zone": "GMT+08:00",​
    "extract_regex": "\\[(\\d{4}\\-\\d{2}\\-\\d{2}T\\d{2}:\\d{2}:\\d{2},\\d{3})\\]",​
    "enable_nanosecond": true​
    }​
    }​
    ]​
    }​
    ​
  • Processing result​
  • The parsed log timestamp is 1715747419123, which is 2024-05-15 12:30:19,123456789.​
  • ​
    "message": "[2024-05-15T12:30:19,123456789] [INFO] java.lang.Exception: exception happened"​
    Log.Time=1715747419123​
    ​
Example 3: Automatically add year information to log time.​
  • Key-value pair logs processed by collection mode or other processor plugins.​
  • ​
    {"message": "[01-01T04:00:00,123456] [INFO] java.lang.Exception: exception happened"}​
    ​
  • LogCollector plugin processor configuration​
  • ​
    {​
    "processors": [​
    {​
    "strp_time": {​
    "field": "message",​
    "format": "%m-%dT%H:%M:%S,%f",​
    "time_zone": "GMT+08:00",​
    "extract_regex": "\\[(\\d{2}\\-\\d{2}T\\d{2}:\\d{2}:\\d{2},\\d{3})\\]",​
    "set_year": "auto"​
    }​
    }​
    ]​
    }​
    ​
  • Processing result​
  • Assume that the system time when processing the log starts is 2023-12-31 20:00:00 (GMT+00:00).​
  • The log query time is 2024-01-01 04:00:00,123.​
  • ​
    "message": "[01-01T04:00:00,123456] [INFO] java.lang.Exception: exception happened"​
    Log.Time=1704052800123​
    ​
​
Last updated: 2026.09.07 15:35:38