-
Notifications
You must be signed in to change notification settings - Fork 55
Custom Log Formats
Starting with Ideolog 0.3.0, users can specify custom formats for log files. This is done in Log Highlighting settings, available in Settings dialog under "Editor".
Ideolog comes with three example formats for Rider backend logs (aka "Pipe-separated"), IDEA logs and TeamCity build logs. In addition, there are several ready-to-use log formats available (see this page to understand how to apply them to Ideolog).
If you have not found a log format that suits your needs, you can create your own.
To enable Ideolog's custom highlighting, you need to provide it with two Java regular expressions and one time format.
The "Message pattern" specifies how to parse a single log event in log file. It should include capture groups for time, severity, category and message. If your log format doesn't have one of these, it's safe to omit them. If your log has any additional fields, such as thread ID, it's also safe to include them as capture groups. This pattern is applied only to visible log lines, so it may be somewhat bulky and slow. In this pattern, '.' also matches newline by default. This is done for ease of matching multi-line messages. Make sure to include "^" at the beginning and "$" at the end.
For example, IntelliJ IDEA
format has the following message pattern:
^([^\[]+)(\[[\s\d]+])\s*(\w*)\s*-\s*(\S*)\s*-(.+)$
to parse log events such as
2022-07-13 10:58:39,385 [6113287] INFO - #c.j.p.r.PhpRunUtil - Output:
where
- first capture group
([^\[]+)
captures date2022-07-13 10:58:39,385
- second capture group
(\[[\s\d]+])
captures thread ID[6113287]
- third capture group
(\w*)
captures severity levelINFO
- fourth capture group
(\S*)
captures category#c.j.p.r.PhpRunUtil
- fifth capture group
(.+)
captures the rest - log messageOutput:
The "Message start pattern" should match lines on which a message starts. It's applied to each line in the log file, and it has to be extremely fast to avoid performance issues. Make sure to include "^" at the beginning, otherwise multi-line messages might match improperly.
The "Time format" specifies how to parse time for time highlighting.
You must specify capture group indices for time, severity and category. Capture groups are numbered starting with 1. If you don't have a capture group for an item, specify 0.
- Category is used to improve "Go To Source" functionality.
- Severity is used to improve "Go To Source" functionality and provide "Go to next error" action.
- Time is used for time highlighting features.
For the IntelliJ IDEA
log example above, we would use
- 1 as a time capture group number
- 3 as a severity capture group number
- 4 as a category capture group number
The "Apply message pattern to all message lines" checkbox was introduced in Ideolog 0.9.0. When it is unchecked, the message pattern is applied only to the first line of the message, and all later lines are automatically considered to be a part of message itself. Otherwise, the message pattern is applied to the whole multi-line message. Leave this unchecked for significantly better performance on logs with lots of multi-line messages.
To detect the format of a log file, all existing patterns are matched against first 25 lines of a file. The one with most matches gets selected. Otherwise, a dumb per-line parser is used.
Because of this, it's recommended to make your patterns as specific as possible. Problems could also arise if your log format starts with lots of unformatted lines. If that is bothering you, feel free to create an issue.
Starting with Ideolog 243.12818.47, if none of the enabled log formats is selected and you have the TextMate Bundles plugin installed and enabled, your log file will be highlighted according to the TextMate bundle for log files, rather than Ideolog.
Right now, there is practically no pattern validation performed. Log formats with invalid patterns are simply ignored. In future versions, more user-friendly interface will be added, possibly with support for previews.
You may need to close and reopen a log file after changing log format settings.