Click here to monitor SSC

FatherJack

SQL Q+A forum at ask.sqlservercentral.com | Follow fatherjack on Twitter

Using LogParser - part 1

Published Monday, May 24, 2010 5:15 PM

I have mentioned LogParser before on my blog and have decided to create a series of walk-through style articles to show someone new to LogParser what it can do and how to use it. It is appropriate to all sorts of job roles in IT, whether you are a System Administrator or a SQL DBA.
LogParser, and all of its documentation, can be downloaded from http://www.microsoft.com/downloads/details.aspx?FamilyID=890cd06b-abf8-4c25-91b2-f8d975cf8c07&displaylang=en and its a very simple installation process.

For the scripts in this series I will work with these files: Person_Address.csv and Sales_SalesOrderDetail.tsv, these are available for download from here as individual zip files or in Everything.zip or you can create your own from the AdventureWorks database by running the script LP_SourceData.sql(also in the zip file) and saving the results from SQL Server Management Studio to C:\LP on your own computer.

Downloaded? Installed? Good, Lets go. Start LogParser2.2 from your Start menu or navigate to and run C:\Program Files\Log Parser 2.2\LogParser.exe and you will have the command prompt-like LogParser interface open as per image01.

LogParser startup
Image 01

As you can see by scrolling up and down the window there is extensive documentation and support within the product, there is also a compiled help file that installs in the same directory that is a great resource if you ever have any need for it. The end of the start up process leaves the following in the window


-h GRAMMAR  : SQL Language Grammar 
-h FUNCTIONS [ ]  : Functions Syntax 
-h EXAMPLES  : Example queries and commands 
-h -i:  : Help on  
-h -o:  : Help on  
-h -c   : Conversion help 
This shows that in the command line simply using the -h switch wil bring you the help you require.

For example, to get help on importing a csv file type, enter LOGPARSER -h -i:csv and you will be rewarded with
Input format: CSV (CSV Format)
Parses text files containing comma-separated values

FROM syntax:

[, ...] |
http:// |
STDIN
Path(s) to CSV file(s)

Parameters:  
  -headerRow  ON|OFF  : Treat first row of each file as a header
(containing field names) [default value=ON]
  -iHeaderFile : File containing header (overrides individual files' header definitions)
  [default value=not specified]
  -iDQuotes  Auto|Ignore : Behavior with double-quoted fields;
  Auto:automatically detect double-quoted fields;
  Ignore:leave double quotes in fields [default value=Auto]
  -fixedFields ON|OFF : Fixed number of fields in the log [default value=ON]
  -nFields  : Number of fields in the log (-1=detect at runtime) [default value=-1]  -
  -dtLines  : Read this amount of lines to detect field types at runtime [default value=10]
  -nSkipLines  : Number of initial lines to skip [default value=0] 
  -comment  : String prefix of comment lines to be skipped [default value=not specified]
  -iCodepage  Input codepage (0=system codepage, -1=UNICODE) [default value=0] 
-iTsFormat    : Format of TIMESTAMP fields [default value=yyyy-MM-dd hh:mm:ss] 
-iCheckpoint : Save checkpoint information to this file [default value=no checkpoint] 
Fields:
Field names and types are retrieved at runtime from the specified input file(s)
Examples:
List the fields extracted from a CSV file:
    LogParser -h -i:CSV myfile.csv -headerRow:on

As you can see, the help available is quite comprehensive and in many cases has several examples so that you can write a successful LogParser script very quickly

Before we go any further, its worth noting that in LogParser all commands start with LOGPARSER, I have no idea why, I just accept it and go along with it.Edit: Many thanks to Chris who has pointed out in the comments that the LogParser that starts every command is calling the executable, that is an unfortunate demonstration of my lack of experience with DOS!

OK, that's almost it for this instalment but I'll leave you with the syntax to let you open up some files and see the contents. This is where its at its most simple, you can view data from a file by starting LogParser and typing LOGPARSER "SELECT * FROM C:\LP\person_address.csv" and their contents of the test.csv file will be listed to you.


In the next part of this series we will review some different output formats and how to control what data is selected. Thanks for reading and please leave a comment if you have any thoughts on the content you find in this blog.

 

by fatherjack
Filed Under: ,

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

 

Jason Haley said:

Interesting Finds: May 25, 2010
May 25, 2010 4:58 AM
 

Chris said:

> Before we go any further, its worth noting that in LogParser all commands start
> with LOGPARSER, I have no idea why, I just accept it and go along with it.

You're kidding, right?

Because the executable is called LOGPARSER.EXE and you just omit the extension when calling it.
May 25, 2010 6:21 AM
 

Dkorzennik said:

I've been using log parser for a number of years now.  For everything from querying IIS logs, to MSCS Cluster logs to Event logs.  The URL attached is one of my blog posts about using it to query event logs to gather boot events.  I do this from powershell.  Calling Logparser from powershell is very straightfoward and leverages all the benefits of the powershell environment.
May 30, 2010 12:51 AM
 

Jonathan Allen said:

So here we are at the last of the series on using LogParser, before we start here is a list of what you...
July 5, 2010 5:49 PM
 

Jonathan Allen said:

This is the third part in a series of articles about using LogParser, specifically from a DBA point of...
July 16, 2010 6:14 PM
 

Jonathan Allen said:

PersonAddress.csv     SalesOrderDetail.tsv     In part 1 of this series we downloaded and installed LogParser...
July 16, 2010 6:14 PM
 

mike said:

how bout running log parser from visual basic? Is it possible or are there any examples?
February 1, 2011 9:14 PM
 

fatherjack said:

@Mike - sure LogParser can be run from VB, I touch on this process briefly in Part 5 of this series here http://www.simple-talk.com/community/blogs/jonathanallen/archive/2010/07/05/93370.aspx. If you have any queries about that then get back in touch.
February 1, 2011 10:57 PM
 

Manohar said:

Hi

Could you please suggest, how to get no of Total RPC and ActiveSync user list in IIS log and out put should chartmode

Please suggest
July 26, 2011 3:47 PM
 

Manohar said:

Hi
can you please suggest, how to get the report total no of RPC user list and active sync user list from IIS log by using logparser.
July 28, 2011 1:59 AM
 

fatherjack said:

@Manohar - Thanks for reading my blog and apologies for the late response to this. I have been unable to log in to this account until now to give you any feedback.

Sadly I am not an IIS expert so will have to suggest that if the information is not in the IIS logs, and I am guessing that RPC details wont be, then you will need to pose your question on a forum such as http://www.iis.net where someone may be able to offer you a solution.

good luck!

July 29, 2011 8:26 PM

What do you think?

(required) 
(optional)
(required) 

About fatherjack

DBA since 1999 working for not-for-profit company. http://twitter.com/fatherjack,
Latest articles
Checking Out SQL Backup Pro 7’s New Automatic Backup Verification
 Wouldn't it be great to offload the daily chore of checking the integrity of your production... Read more...

Chuck Lathrope: DBA of the Day
 Chuck Lathrope was a finalist for the Exceptional DBA of the Year award in 2009. We contacted him to... Read more...

Backups, What Are They Good For?
 Pixar recently confessed, in an engaging video, that Toy Story 2 was almost lost due to a bad backup,... Read more...

C# Async: What is it, and how does it work?
 The biggest new feature in C#5 is Async, and its associated Await (contextual) keyword. Anybody who is... Read more...

SQL Server 2012 AlwaysOn
 SQL Server AlwaysOn provides a high-availability and Disaster-recovery solution for SQL Server 2012. It... Read more...