Log Parser is often used to parse logs that grow over time.
For example, the IIS logs and the Windows Event Log are
continuously updated with new information, and in some cases, we
would like to parse these logs periodically and only retrieve the
new records that have been logged since the last time.
This is especially true for scenarios in which, for example, we use
Log Parser to consolidate logs to a database in an almost real-time
fashion, or when we use Log Parser to build a monitoring system
that periodically scans logs for new entries of interest.
For these scenarios, Log Parser offers a feature that allows
sequential executions of the same query to only process new data
that has been logged since the last execution.
This feature can be enabled with the iCheckPoint parameter
of the following input formats:
The "iCheckPoint" parameter is used to specify the name of a
"checkpoint" file that Log Parser uses to store and retrieve
information about the "position" of the last entry parsed from each
of the logs that appear in a command.
When we execute a command with a checkpoint file for the first time
(i.e. when the specified checkpoint file does not exist), Log
Parser executes the query normally and processes all the logs in
the command, saving for each the "position" of the last parsed
entry to the checkpoint file.
If later on we execute the same command specifying the same
checkpoint file, Log Parser will parse again all the logs in the
command, but each log will be parsed starting after the
entry that was last parsed by the previous command, thus producing
records for new entries only. When the new command execution is
complete, the information in the checkpoint file is updated with
the new "position" of the last entry in each log.
Note: Checkpoint files are updated only when a query executes succesfully. If an error causes the execution of a query to abort, the checkpoint file is not updated.
To make an example, let's assume that the "MyLogs" folder
contains the following text files:
logparser "SELECT * FROM MyLogs\*.*" -i:TEXTLINE -iCheckPoint:myCheckPoint.lpcWhen this command is executed for the first time, Log Parser will return all the 200 lines from all of the four log files, and it will create the "myCheckPoint.lpc" checkpoint file containing the position of the last line in each of the four log files.
Tip: When the checkpoint file is specified without a path, Log Parser will create the checkpoint file in the folder currently set for the %TEMP% environment variable, usually "\Documents and Settings\<user name>\Local Settings\Temp".
Let's now assume that the "Log3.txt" file is updated, and that ten new lines are added to the log file.Log Files | Checkpoint file |
Log1.txt, 50 lines | Log1.txt, line 50 |
Log2.txt, 100 lines | Log2.txt, line 100 |
Log3.txt, 30 lines | Log3.txt, line 20 |
Log4.txt, 30 lines | Log4.txt, line 30 |
Log Files | Checkpoint file |
Log1.txt, 50 lines | Log1.txt, line 50 |
Log2.txt, 100 lines | Log2.txt, line 100 |
Log3.txt, 30 lines | Log3.txt, line 30 |
Log4.txt, 30 lines | Log4.txt, line 30 |
Log5.txt, 10 lines | not recorded |
Log Files | Checkpoint file |
Log1.txt, 50 lines | Log1.txt, line 50 |
non-existing | Log2.txt, line 100 |
Log3.txt, 30 lines | Log3.txt, line 30 |
Log4.txt, 30 lines | Log4.txt, line 30 |
Log5.txt, 10 lines | Log5.txt, line 10 |
Log Files | Checkpoint file |
Log1.txt, 50 lines | Log1.txt, line 50 |
Log3.txt, 30 lines | Log3.txt, line 30 |
Log4.txt, 30 lines | Log4.txt, line 30 |
Log5.txt, 10 lines | Log5.txt, line 10 |
Log Files | Checkpoint file |
Log1.txt, 10 lines | Log1.txt, line 50 |
Log3.txt, 30 lines | Log3.txt, line 30 |
Log4.txt, 30 lines | Log4.txt, line 30 |
Log5.txt, 10 lines | Log5.txt, line 10 |
Log Files | Checkpoint file |
Log1.txt, 10 lines | Log1.txt, line 10 |
Log3.txt, 30 lines | Log3.txt, line 30 |
Log4.txt, 30 lines | Log4.txt, line 30 |
Log5.txt, 10 lines | Log5.txt, line 10 |
logparser "SELECT COUNT(*) AS Total FROM MyLogs\*.*" -i:TEXTLINE -iCheckPoint:myCheckPoint.lpcWhen the command is executed for the first time, the "Total" field in the output record returned by the query will be equal to 200, that is, the total number of lines in the four log files.
logparser "SELECT SUM(Total) FROM FirstResults.csv, LastResults.csv" -i:CSV
© 2004 Microsoft Corporation. All rights reserved.