Another Tcl Logger Proc

Scott Nichols Below is a Tcl logger proc that I wrote a while back. It puts the log to screen with a date and time in front of the screen print. If logging is on then the log is saved to file too with the date and time in front of 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 {

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

        if { $logging } {
            # Get the current day out of the month
            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\""
    }
}

Emmanuel Frecon Yet another logging facility is available in outlog - Taking care of log rotations automagically.