lnav icon indicating copy to clipboard operation
lnav copied to clipboard

Two questions

Open bubnov opened this issue 5 months ago • 5 comments

Hi,

Got two questions:

  • Is it possible to skip formatters at all? Just show log lines as is (with optional ascii coloring), but use all benefits of lnav?
  • Is it possible to set the line format for non-json log formats?

bubnov avatar Sep 01 '25 11:09 bubnov

  • Is it possible to skip formatters at all? Just show log lines as is (with optional ascii coloring), but use all benefits of lnav?

If a file does not match a log format, it is shown in the TEXT view. But, the majority of features will not work. Most parts of lnav depend on knowing where a log message starts and stops as well as the timestamp. The log format defines the patterns that denote the start of a log message.

  • Is it possible to set the line format for non-json log formats?

Not at the moment. Issue #1309 tracks this request.

tstack avatar Sep 01 '25 13:09 tstack

Most parts of lnav depend on knowing where a log message starts and stops as well as the timestamp.

Is it possible to add a super-minimal formatter that just has one regex for the timestamp extraction and consider the end of line as the stop of the message?

bubnov avatar Sep 01 '25 13:09 bubnov

Is it possible to add a super-minimal formatter that just has one regex for the timestamp extraction and consider the end of line as the stop of the message?

The builtin generic_log format has a bunch of regexes to try to capture really basic shapes of log messages.

Otherwise, I would say it's pretty straightforward to create a custom log format using the regex101 integration:

  1. Find a log line that is representative
  2. Ask chatgpt to create a regex from that log line
  3. Copy the regex and sample line into regex101
  4. Tweak the regex, if necessary
  5. Save the regex in regex101 to create a unique URL
  6. Run lnav -m regex101 import <regex101-url> mylog (after replacing the URL) to create the format file

(I think I recently tried asking chatgpt to create the lnav format file, but it didn't do it right...)

tstack avatar Sep 01 '25 14:09 tstack

it's pretty straightforward to create a custom log format

I agree, it is not hard. Though I found a few unfortunate glitches:

  • sometimes lnav permanently hangs (closing the terminal is the only fix)

  • sometimes lnav falls back to the syslog_log formatter, though I have a plain text logs such as:

    2025-09-01T17:42:50.875833+0300 DEBUG tokio-runtime-worker backend::client: macos: >>> Data { None }
    

    I think this could be fixed using explicit formatter like lnav -m some_formatter.

  • and the most annoying one: I can't set custom format for the text logs, which you mentioned in the answer to the second question.

Except for that, the lnav is awesome! Thanks!

bubnov avatar Sep 01 '25 14:09 bubnov

  • sometimes lnav permanently hangs (closing the terminal is the only fix)

That sounds bad, can you give some details? What version are you running? If you pass -d /tmp/lnav.dbg to lnav, it will generate a debug log that might tell me what's wrong.

  • sometimes lnav falls back to the syslog_log formatter, though I have a plain text logs such as:

Hmm, the line you gave is detected as generic_log for me. Anyhow, making the format's regex more specific can help fix issues like this. If the regex is more specific than ones in other formats, it will be tested before the others.

If you want to attach the format you're trying and some sample logs to this issue, I can take a look at it.

I think this could be fixed using explicit formatter like lnav -m some_formatter.

See this FAQ entry

tstack avatar Sep 03 '25 13:09 tstack