Version 0 of Another Tcl Logger Proc

Updated 2004-09-30 03:48:28

Scott Nichols Below is a Tcl logger proc that I wrote a while back. It does the following screen puts the log to screen with a date and time in front of the screen put. If logging is on the log is saved to file with the date and time to each write. A new log file is automatically created the first log after midnight.

 proc log { value {logging true} {logPath ./} } {
    global yesterday fileid
    if { [catch {

        puts "[clock format $seconds -format "%D|%T|"]$value"

        if { $logging } {
            # Get the current day out of the month
            set currentday [clock seconds]
            set seconds $currentday
            set currentday [clock format $currentday -format %d]

            if { ! [info exists fileid] } {
                set fileid [open "${logPath}/ReaderBoard [clock format $seconds -format %m-%d-%y].txt" a+]
            }

             # Create new file
             if { [info exists yesterday] } {

                 if { $currentday != $yesterday } {
                     set yesterday $currentday
                     close $fileid
                     set fileid [open "${logPath}/ReaderBoard [clock format $seconds -format %m-%d-%y].txt" a+]
                 }
             } else {
                 set yesterday $currentday
             }

            puts $fileid "[clock format $seconds -format "%D|%T|"]$value"        

        }
    } errorString] } {
        puts "proc log ERROR: \"$errorString\""
    }
 }