Version 10 of LogParser

Updated 2006-02-11 00:12:58

Jorge Moreno 2006-02-10 - 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...

I am currently working on a GUI for this Parser...made in Tcl of course :^)


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)

what I have:

  • the header definition file in C:\headerHP.csv, with the following contents:
 operator  date  sn  tester  status  model  tt
  • the LogParser itself in "C:/Archivos de programa/Log Parser 2.2/LogParser.exe\"
  • the default query file called "HP_query2.sql", with the following contents:
 SELECT tester,model,COUNT(*) AS qty
 FROM C:\uptime_*
 WHERE status = 'F' AND date > 60210070000
 GROUP BY tester,model
 ORDER BY Qty DESC
  • the target file names start with "uptime..." and are located in "C:\"

you can also see that my target files use a weird date format (number without separation symbols)

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's: e'get and K used in


 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] {
   if [regexp {^\s*proc } $line] {
         set tag blue
   } elseif {[regexp {^\s*#} $line]} {
         set tag red
   } else {set tag ""}
   .ctrls.sql insert end $line\n $tag
 }
 }

 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


 #set header [file nativename [tk_getOpenFile]]
 #set header [tk_getOpenFile]
 set header "C:/headerHP.csv"
 set query "HP_query2.sql"
 .ctrls.qryPath insert end "[pwd]/HP_query2.sql" 
 set name "[pwd]/HP_query2.sql"
 showSQL $name


 proc Run {} {
   global input log but command header query
   $log insert end "-\n"
   puts [pwd]
   if {[catch {open "|\"C:/Archivos de programa/Log Parser 2.2/LogParser.exe\"\
                -i:TSV file:$query\
                -iSeparator:space\
                -nSep:2\
                -iTsFormat \"yyMMddhhmmss\"\
                -iHeaderFile $header" 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...."
        $log insert end $line\n
        $log see end
        catch {close $input}
        $but config -text "run" -command Run
        set chart [image create photo -file C:/tclCode/MisTcls/Events.gif]
        .c create image 300 200 -image $chart
 }