TPL Output Format Template Files
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.
Raw Format Templates
In the raw format, the three template sections are specified as three different files.The template file containing the body section is specified using the tpl parameter, while the optional header and footer sections are specified with the tplHeader and tplFooter parameters, respectively.
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.
Structured Format Templates
In the structured format, a single template file contains the header, body, and footer sections, each enclosed within special <LPHEADER>, <LPBODY>, and <LPFOOTER> tags that mark the boundaries of each section.Structured format template files are specified using the tpl parameter.
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.
Template Variables
The following table lists the variables that are available to template files: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 |
- Notes:
- (1): When a variable matches both a field name and an environment variable, the field value is substituted.
© 2004 Microsoft Corporation. All rights reserved.