Version 31 of LogParser

Updated 2009-07-05 03:55:28 by Jorge

Jorge Moreno 2006-02-10 - Here is a frontend for LogParser
(from M$, http://www.microsoft.com/technet/scriptcenter/tools/logparser/default.mspx )

Very powerful parser, from what I reviewed and tried:

  • Very Fast
  • SQL like query definition
  • output to a file, console, chart, Database
  • multiple text files treated as a single set of data
  • handles various file types (CSV, TSV, etc)
  • much more...

Some Details:

There are commonly 3 files to define:

  • The target file(s)
  • The file that define the header (if header is not part of your target file)
  • The file that define the SQL string (if you do not want to include the SQL in the command line)

This is a script far from being complete, but could serve as a reference (it is operational in my particular setup of files)

Dependecies in this example:

  • the header definition file is header.txt, with the following contents:
 operator  date  sn  tester  status  model  tt
  • the LogParser itself in "C:/Program Files/Log Parser 2.2/LogParser.exe\"
  • the default query file called "query.sql", with the following contents:
 SELECT TOP 4 * FROM logParserGUI.tcl WHERE status = 'F'
  • the target file is this script itself, you will see this data, at the top, commented out of course!
 operator  060109083012  serialnumber1  icthp5  P  ModelA  228.979
 operator  060109083146  serialnumber2  icthp5  F  ModelA  65.318
 operator  060109083438  serialnumber3  icthp5  P  ModelA  129.215
 operator  060109083711  serialnumber4  icthp5  P  ModelA  136.301

I will eventually clean all these dependencies to run the script, I just wanted to throw it so it could be useful to someone...

You will also see some code from this wiki, like RS's proc e'get used in e: a tiny editor plugin for eTcl


JM 2006-Feb-13 cleaning up a little bit


JM 2006-Nov-4 just added stderr output to a file if there is any error message coming from LogParser


  #operator  060109083012  serialnumber1  icthp5  P  ModelA  1
  #operator  060109083146  serialnumber2  icthp5  F  ModelA  2
  #operator  060109083438  serialnumber3  icthp5  P  ModelA  3
  #operator  060109083711  serialnumber4  icthp5  P  ModelA  4
 console show
 set types {*.sql}

 proc e'get name {
   if [file exists $name] {
      set f [open $name]
      set ::g(filename) $name
      K [read $f] [close $f]
   } else {corp $name}
 }

 proc K {a b} {set a}

 proc showSQL sqlFile {
 .ctrls.qryPath delete 0 end
 .ctrls.qryPath insert end $sqlFile
 .ctrls.sql delete 1.0 end
    foreach line [split [e'get $sqlFile] \n] {
      .ctrls.sql insert end $line\n
    }
 }

 frame .t
 frame .ctrls
 set log [text .t.log -width 80 -height 30 \
   -borderwidth 2 -relief raised -setgrid true \
   -yscrollcommand {.t.scroll set}]
 scrollbar .t.scroll -command {.t.log yview}
 canvas .c -height 20 -width 640
 set but [button .ctrls.run -text "run" -command Run]
 button .ctrls.qry -text "Select Query..." -command         {set query [tk_getOpenFile -filetypes [list   [list "All files" $types]]]
                                                         showSQL $query
                                                         }
 entry .ctrls.qryPath -width 50
 button .quit -text "exit" -command exit
 text .ctrls.sql -width 40 -height 10

 pack .quit
 pack .t.scroll -side right -fill y
 pack .t.log -side left -fill both -expand true
 pack .t -side top -fill both -expand true
 pack .c
 grid .ctrls.qry .ctrls.qryPath
 grid .ctrls.run .ctrls.sql
 pack .ctrls

 #default header file
 set header "[pwd]/header.txt"
 #default query file
 set query "[pwd]/query.sql"

 if [file exists $query] {
    .ctrls.qryPath insert end $query
    showSQL $query
 } else {
        tk_messageBox -message "There is no default query file defined\n
                              ($query was expected)"
 }

 proc Run {} {
   global input log but command header query
   $log insert end "-\n"
   puts [pwd]
   if {[catch {open "|\"C:/Program Files/Log Parser 2.2/LogParser.exe\" \
                -i:TSV file:$query\
                -headerRow:OFF\
                -iSeparator:space\
                -nSep:2\
                -iTsFormat \"yyMMddhhmmss\"\
                -iHeaderFile $header 2> errfile.txt" r+} input]} {
      $log insert end "$input\n"
   } else {
      fconfigure $input -blocking 0 -buffering none -translation auto
      fileevent $input readable Log
      $but config -text Stop -command Stop
   }
 }

 proc Log {} {
   global input log
   if [eof $input] {
      Stop
   } else {
        gets $input line
        $log insert end ">>> $line\n"
        $log see end
   }
 }

 proc Stop {} {
        global input log but
        set line "done....\if there is LogParser errors, see: errfile.txt"
        $log insert end $line\n
        $log see end
        catch {close $input}
        $but config -text "run" -command Run
 }

7/4/2009, JM LogParser goes COM


Fetching backrefs...