Template files are divided into three sections: an optional
header section that is written once at the beginning of the
output, a body section that is written repeatedly for each
output record, and an optional footer section that is
written once at the end of the output.
The body section can contain special variables that are substituted at run time with
values computed during the execution of the query, such as values
and names of output record fields, and the number of fields in the
output records.
The header and footer sections can contain the same variables
available to the body section, except for those that refer to
values of output record fields.
Template files can be specified in two different ways: as raw format templates, or as structured format templates.
The following is a sample raw format template file containing the body section:
The Url %cs-uri-stem%, requested by %c-ip%, took %time-taken% milliseconds to execute. It was requested at %time% o’clock.The following command parses an IIS log file and creates a text file formatted according to the template file:
LogParser "SELECT * INTO out.txt FROM extend1.log" -o:TPL -tpl:mytemplate.tplThe resulting output will look like the following example:
The Url /default.htm, requested by 192.168.1.102, took 24 milliseconds to execute. It was requested at 04:23:45 o’clock. The Url /mydocuments/index.html, requested by 192.168.1.104, took 134 milliseconds to execute. It was requested at 04:23:47 o’clock. The Url /mydocuments/styles/style.css, requested by 192.168.1.101, took 49 milliseconds to execute. It was requested at 04:23:48 o’clock.
The following is a sample structured format template file:
<LPHEADER>This is my template, for a query containing %FIELDS_NUM% fields, executed by %USERNAME%.</LPHEADER> Some ignored comment here. <LPBODY>The Url %cs-uri-stem%, requested by %c-ip%, took %time-taken% milliseconds to execute. It was requested at %time% o’clock. </LPBODY> <LPFOOTER>End of report. </LPFOOTER>The following command parses an IIS log file and creates a text file formatted according to the template file:
LogParser "SELECT * INTO out.txt FROM extend1.log" -o:TPL -tpl:mytemplate.tplThe resulting output will look like the following example:
This is my template, for a query containing 32 fields, executed by TestUser. The Url /default.htm, requested by 192.168.1.102, took 24 milliseconds to execute. It was requested at 04:23:45 o’clock. The Url /mydocuments/index.html, requested by 192.168.1.104, took 134 milliseconds to execute. It was requested at 04:23:47 o’clock. The Url /mydocuments/styles/style.css, requested by 192.168.1.101, took 49 milliseconds to execute. It was requested at 04:23:48 o’clock. End of report.
Note: The TPL output format assumes that the character immediately following the opening tag for a section, such as <LPBODY>, belongs to that section.
Variable | Description | Example Template | Example Output | Section |
---|---|---|---|---|
Value of the output record field with the specified 1-based index | First field value:
|
First field value: Service Control Manager | Body | |
Value of the specified output record field | First field value:
|
First field value: Service Control Manager | Body | |
Name of the output record field with the specified 1-based index | SourceName value: Service Control Manager | Header, Body, Footer | ||
Number of output record fields | There are |
There are 32 fields. | Header, Body, Footer | |
Current system date and time, in UTC coordinates | Generated at
|
Generated at 2004-11-06 02:56:37 | Header, Body, Footer | |
Value of the specified environment
|
Generated by |
Generated by TestUser | Header, Body, Footer |
© 2004 Microsoft Corporation. All rights reserved.