* Added simple filter support

This commit is contained in:
Andreas Schneider 2015-09-28 09:54:03 +02:00
parent e14df6a75d
commit d0633ccb83
2 changed files with 55 additions and 18 deletions

View File

@ -64,36 +64,59 @@ procedure TLogFilterApplication.DoRun;
var
commandFile: TextFile;
line: String;
fg, bg: Byte;
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
WriteHelp;
Terminate;
Exit;
end;
FCommandFileName := GetOptionValue('c', 'commandfile');
if not FileExists(FCommandFileName) then
if HasOption('c', 'commandfile') then
begin
Writeln('Commandfile not found: ', FCommandFileName);
ExitCode := 1;
Terminate;
Exit;
end;
FCommandFileName := GetOptionValue('c', 'commandfile');
AssignFile(commandFile, FCommandFileName);
Reset(commandFile);
if not FileExists(FCommandFileName) then
begin
Writeln('Commandfile not found: ', FCommandFileName);
ExitCode := 1;
Terminate;
Exit;
end;
// Parse command file first
while not EOF(commandFile) do
AssignFile(commandFile, FCommandFileName);
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
Readln(commandFile, line);
if FCommandMatcher.Exec(line) then
ProcessCommand(FCommandMatcher.Match[1], FCommandMatcher.Match[3]);
end;
FCurrentLineFilter := TLineFilter.Create(GetOptionValue('s', 'simple'));
FLineFilters.Add(FCurrentLineFilter);
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
FLogFileName := GetOptionValue('f', 'logfile');
@ -379,12 +402,16 @@ begin
Writeln('Options:');
Writeln(' -c --commandfile=<filename>');
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(' specifies the logfile to be parsed');
Writeln(' -p --poll');
Writeln(' keep the log file open and wait for data');
Writeln(' --html=<filename>');
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(' show this help screen');
end;

View File

@ -37,6 +37,7 @@ type
BGColor: Byte;
Group: Byte;
constructor Create(AString: String);
constructor Create(AExpression: String; AFG, ABG, AGroup: Byte);
destructor Destroy; override;
class var
FilterExpression: TRegExpr;
@ -104,6 +105,15 @@ begin
Expression := TRegExpr.Create(AString);
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;
begin
Expression.Free;