* Added simple filter support
This commit is contained in:
parent
e14df6a75d
commit
d0633ccb83
63
UApp.pas
63
UApp.pas
|
@ -64,36 +64,59 @@ procedure TLogFilterApplication.DoRun;
|
||||||
var
|
var
|
||||||
commandFile: TextFile;
|
commandFile: TextFile;
|
||||||
line: String;
|
line: String;
|
||||||
|
fg, bg: Byte;
|
||||||
begin
|
begin
|
||||||
if HasOption('h', 'help') or not HasOption('c', 'commandfile') then
|
if HasOption('h', 'help') or (not HasOption('c', 'commandfile') and not
|
||||||
|
HasOption('s', 'simple')) then
|
||||||
begin
|
begin
|
||||||
WriteHelp;
|
WriteHelp;
|
||||||
Terminate;
|
Terminate;
|
||||||
Exit;
|
Exit;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
FCommandFileName := GetOptionValue('c', 'commandfile');
|
if HasOption('c', 'commandfile') then
|
||||||
|
|
||||||
if not FileExists(FCommandFileName) then
|
|
||||||
begin
|
begin
|
||||||
Writeln('Commandfile not found: ', FCommandFileName);
|
FCommandFileName := GetOptionValue('c', 'commandfile');
|
||||||
ExitCode := 1;
|
|
||||||
Terminate;
|
|
||||||
Exit;
|
|
||||||
end;
|
|
||||||
|
|
||||||
AssignFile(commandFile, FCommandFileName);
|
if not FileExists(FCommandFileName) then
|
||||||
Reset(commandFile);
|
begin
|
||||||
|
Writeln('Commandfile not found: ', FCommandFileName);
|
||||||
|
ExitCode := 1;
|
||||||
|
Terminate;
|
||||||
|
Exit;
|
||||||
|
end;
|
||||||
|
|
||||||
// Parse command file first
|
AssignFile(commandFile, FCommandFileName);
|
||||||
while not EOF(commandFile) do
|
Reset(commandFile);
|
||||||
|
|
||||||
|
// Parse command file first
|
||||||
|
while not EOF(commandFile) do
|
||||||
|
begin
|
||||||
|
Readln(commandFile, line);
|
||||||
|
if FCommandMatcher.Exec(line) then
|
||||||
|
ProcessCommand(FCommandMatcher.Match[1], FCommandMatcher.Match[3]);
|
||||||
|
end;
|
||||||
|
|
||||||
|
CloseFile(commandFile);
|
||||||
|
end; //commandfile processing
|
||||||
|
|
||||||
|
if HasOption('s', 'simple') then
|
||||||
begin
|
begin
|
||||||
Readln(commandFile, line);
|
FCurrentLineFilter := TLineFilter.Create(GetOptionValue('s', 'simple'));
|
||||||
if FCommandMatcher.Exec(line) then
|
FLineFilters.Add(FCurrentLineFilter);
|
||||||
ProcessCommand(FCommandMatcher.Match[1], FCommandMatcher.Match[3]);
|
|
||||||
end;
|
|
||||||
|
|
||||||
CloseFile(commandFile);
|
if HasOption('fg') then
|
||||||
|
fg := StrToIntDef(GetOptionValue('fg'), $FF)
|
||||||
|
else
|
||||||
|
fg := LightBlue;
|
||||||
|
|
||||||
|
if HasOption('bg') then
|
||||||
|
bg := StrToIntDef(GetOptionValue('bg'), $FF)
|
||||||
|
else
|
||||||
|
bg := $FF;
|
||||||
|
|
||||||
|
FCurrentLineFilter.Filters.Add(THighlightFilter.Create('.*', fg, bg, 0));
|
||||||
|
end; //Simple Mode
|
||||||
|
|
||||||
if HasOption('f', 'logfile') then
|
if HasOption('f', 'logfile') then
|
||||||
FLogFileName := GetOptionValue('f', 'logfile');
|
FLogFileName := GetOptionValue('f', 'logfile');
|
||||||
|
@ -379,12 +402,16 @@ begin
|
||||||
Writeln('Options:');
|
Writeln('Options:');
|
||||||
Writeln(' -c --commandfile=<filename>');
|
Writeln(' -c --commandfile=<filename>');
|
||||||
Writeln(' specifies the filename with filter commands');
|
Writeln(' specifies the filename with filter commands');
|
||||||
|
Writeln(' -s --simple=<pattern>');
|
||||||
|
Writeln(' Applies a simple filter and highlights the (full) match.');
|
||||||
Writeln(' -f --logfile=<filename>');
|
Writeln(' -f --logfile=<filename>');
|
||||||
Writeln(' specifies the logfile to be parsed');
|
Writeln(' specifies the logfile to be parsed');
|
||||||
Writeln(' -p --poll');
|
Writeln(' -p --poll');
|
||||||
Writeln(' keep the log file open and wait for data');
|
Writeln(' keep the log file open and wait for data');
|
||||||
Writeln(' --html=<filename>');
|
Writeln(' --html=<filename>');
|
||||||
Writeln(' outputs filtered results in a formatted HTML file');
|
Writeln(' outputs filtered results in a formatted HTML file');
|
||||||
|
Writeln(' --fg=<color> --bg=<color>');
|
||||||
|
Writeln(' Sets the highlight color for the simple matcher (-s)');
|
||||||
Writeln(' -h --help');
|
Writeln(' -h --help');
|
||||||
Writeln(' show this help screen');
|
Writeln(' show this help screen');
|
||||||
end;
|
end;
|
||||||
|
|
10
UFilter.pas
10
UFilter.pas
|
@ -37,6 +37,7 @@ type
|
||||||
BGColor: Byte;
|
BGColor: Byte;
|
||||||
Group: Byte;
|
Group: Byte;
|
||||||
constructor Create(AString: String);
|
constructor Create(AString: String);
|
||||||
|
constructor Create(AExpression: String; AFG, ABG, AGroup: Byte);
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
class var
|
class var
|
||||||
FilterExpression: TRegExpr;
|
FilterExpression: TRegExpr;
|
||||||
|
@ -104,6 +105,15 @@ begin
|
||||||
Expression := TRegExpr.Create(AString);
|
Expression := TRegExpr.Create(AString);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
constructor THighlightFilter.Create(AExpression: String; AFG, ABG, AGroup: Byte
|
||||||
|
);
|
||||||
|
begin
|
||||||
|
FGColor := AFG;
|
||||||
|
BGColor := ABG;
|
||||||
|
Group := AGroup;
|
||||||
|
Expression := TRegExpr.Create(AExpression);
|
||||||
|
end;
|
||||||
|
|
||||||
destructor THighlightFilter.Destroy;
|
destructor THighlightFilter.Destroy;
|
||||||
begin
|
begin
|
||||||
Expression.Free;
|
Expression.Free;
|
||||||
|
|
Loading…
Reference in New Issue