Guides › Text
Filtering a log or file: Line Filter or Log Viewer?
Two tools here cut a long file down to what you need, and they see it differently. The Line Filter sees lines of text and applies your rules to each one. The Log Viewer sees log entries: each has a level and a time, and a stack trace belongs to the line above it. Both run in your browser, so a log’s names, addresses and tokens stay on your device.
1. Which one to use
Use the Log Viewer when:
- you want entries at some levels, such as errors and warnings, and not others;
- you want a time window, such as the minutes either side of a failure, or times shown in your own time zone;
- entries run over several lines (stack traces, wrapped messages) and must stay whole;
- the log is long: it shows 2,000 entries at a time, and Copy these and Save these take them all;
- it has terminal colour codes, or is a JSON log with
leveland time fields.
Use the Line Filter when:
- the file isn’t a log, or its lines have no level or time: a config file, a list, an export, command output;
- the rule is about how a line starts or ends, or that it’s exactly some text;
- you need to say what to leave out (lines that don’t contain something), or more than one rule at once;
- you want lines around each match, or each line’s number in the original, as
grep -Candgrep -ngive; - the file’s name doesn’t end in a log extension, such as
app.log.1: the Log Viewer’s file box only takes text and log files.
If filtering is only one step of a tidy-up, along with trimming spaces, removing duplicates or sorting, the Text Cleaner’s Keep or remove lines that match step does it in the same recipe.
2. Filter by line rules
In the Line Filter, each rule keeps or removes lines that start with, end with, contain, are exactly or match a regular expression, or that don’t. For each line, the rules are checked from the top and the first that matches decides. Lines no rule matches are removed if any rule keeps lines, and kept otherwise.
So put exceptions first. To keep the errors but not the ones about a known disk warning, add Remove lines that
contain disk, then Keep lines that contain error. The other way round, the keep rule takes every
error before the remove rule sees it. Each rule shows how many lines it decided, so a rule that never gets a line
shows 0 lines.
3. Filter by level, time and entry
Drop the log on the Log Viewer. Untick the levels you don’t want, set From and To around the time that
matters, and type a word or a /regular expression/i in Contains. An entry with a stack trace folds open, and
the whole entry is kept or left out together. Reading a crash or a log goes further,
into the stack trace and the times.
4. Using both
The Log Viewer keeps one Contains condition. When you need more, narrow the log by level and time there, use Save these, then open the saved file in the Line Filter for rules it can’t express, such as an exception or a line ending. Do it in that order: the Line Filter splits a stack trace into separate lines, which the Log Viewer would then no longer keep together. Line numbers in the Line Filter count from the file you give it, so after this they’re numbers in the saved file, not the original log.
All 62 guides, grouped by what they help with.
Saved you a few minutes? Say thanks with a coffee.
Something wrong or unclear in this guide? Report it or suggest a guide.