doublep / logview

Emacs mode for viewing log files
GNU General Public License v3.0
153 stars 18 forks source link

[Help] How to write format for thread name which do not have starter and terminator? #48

Closed chuxubank closed 11 months ago

chuxubank commented 11 months ago
2023-07-19 14:10:02.736 GMT+08:00 DEBUG T: Subscription Manager Consumer Thread LottieLockView - loading from filesystem
2023-07-19 14:10:02.739 GMT+08:00 DEBUG T: pool-40-thread-1 LottieLockView - starting to play t4.json

Here is an example from my log, and my config is: TIMESTAMP IGNORED LEVEL T: THREAD NAME - MESSAGE But some threads like: Subscription Manager Consumer Thread have space in their name.

How can I deal with these thread names? Currently these thread names are all end with 'Thread'

doublep commented 11 months ago

This is currently not possible without major hacks. In principle, I think I could implement something to deal with this too, but maybe you should instead consider tweaking log format, because it currently looks confusing. If you can influence that, of course.

chuxubank commented 11 months ago

Thanks! This format do looks confusing but there are plenty of old logs we still need to deal with. I will try to modify the log format for new logs.

Maybe we can custom the thread name regexp or even giving an option for users to custom the whole regexp with group to match an entry and provide the group order to match each part?

The other option may let user choose which part is the most greedy part?

Anyway, thanks for your help and this great package!

doublep commented 11 months ago

Regexp for the whole entry cannot be specified, because timestamp, level and message are handled specially and I don't want to give users access to this (would mean less flexibility in future). However, it is now possible to specify regexp for certain parts (name, thread and "ignored") in case the automatic one (derived from separators) is not good enough. Regexp must not contain matching groups, but may contain any number of shy groups.

In particular, your example should now be handled by this format (I also added this as a regression test):

    TIMESTAMP IGNORED LEVEL T: <<RX:THREAD:[^-]+>> NAME - MESSAGE

The syntax is pretty verbose, but I chose it that way because it should really not be needed in 99% of cases. Can also be sort of misused for kinda-escaping like this: <<RX:IGNORED:THREAD>> would match literal string "THREAD" and ignore it.

You can wait a couple of days for 0.17, install from MELPA.Unstable or just from GitHub sources. Will close with 0.17.

chuxubank commented 11 months ago
image

Thanks for your great help!

I tried the latest MELPA.Unstable but face some issue, with your provided format. The first two lines work well, but the old line which works before, not matched any more. Do I need change the formant you provided?

2023-07-19 14:10:02.739 GMT+08:00 DEBUG T: pool-40-thread-1 LottieLockView - starting to play t4.json
doublep commented 11 months ago

Indeed, I overlooked this. However, this is only because [^-]+ regexp part wouldn't match hyphens, not because of problems in the code itself. I suggest to replace it with .+? then, i.e. "match anything, but don't be greedy". I initially looked at that "-" before the message, but forgot that thread name itself could contain hyphens.

chuxubank commented 11 months ago

Haha, I think so! It works well now, thanks again!

doublep commented 11 months ago

Released as part of 0.17.