carina-studio / ULogViewer

Cross-Platform Universal Log Viewer.
https://carina-studio.github.io/ULogViewer/
MIT License
409 stars 40 forks source link

can regexp support multiline ? #40

Open Quenii opened 7 months ago

Quenii commented 7 months ago

I tried something like: \d+-\d+\n\w+ \n doesn't work

hamster620 commented 7 months ago

@Quenii You can refer to #31 for defining log patterns for multiple lines. Or you can provide a sample log file you want to parse so that we can check the question. Thanks.

Quenii commented 7 months ago

i've tried #31, but haven't figured out the logic

(?<TimeSpan>\d+)\-(?<Extra1>\d+)\-(?<Extra2>\d+)\-(?<Extra3>\d+)\-\d+\-\d+\-\d+\-\d+\-\d+\-\d+\-\d+\-\d+ : Modeno:(?<Extra4>.*) to match 4377-3-15092-291-34-1-1440-1449-107-0-0-254 : Modeno:HQ SSD 4000GB

(?<TimeSpan>\d+)\-(?<Extra1>\d+)\-(?<Extra2>\d+)\-(?<Extra3>\d+)\-\d+\-\d+\-\d+\-\d+\-\d+\-\d+\-\d+\-\d+ : UNC. lba:(?<Extra5>\w+) paa:0x(?<Extra6>\w+).*d:(?<Extra7>\d+).* to match 123392-234-15057-291-34-2-5605376-6523805-176-0-0-254 : UNC. lba:9801C0 paa:0xFF2A98 b:136 p:811 d:7 uncM:0-20000000_FFFF,..

while I've tons of lines to match, can't figure out which is repeatable or skippable pasted some clip of my log

Untitled-1.txt

hamster620 commented 7 months ago

@Quenii According to the log file you provided, I assume that every log starts with \d+(\-\d+)+ and all following lines which NOT start with \d+(\-\d+)+ should be treat as multi-line message. Then we can define 2 log patterns to parse logs:

  1. (?<Extra1>\d+(\-\d+)+)\s*:\s*(?<Message>.*) which defines the start of log.
  2. ^(?!\d+(\-\d+)+)(?<Message>.*) defines message to concatenate after. The pattern is repeatable because it can be presented more than 1 times, and skippable because the line may not always be presented.

You can import and refer to the log profile: GitHub#41.json

Quenii commented 6 months ago

thanks a lot the json you provided works but what I want is to parse more data from message field ie, several Extra I posted above

hamster620 commented 6 months ago

thanks a lot the json you provided works but what I want is to parse more data from message field ie, several Extra I posted above

@Quenii What output you want to see in the log viewer based-on the log you provided?