logtofile.tcl
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 package require logger
00014
00015
00016 ret log_to_file (type lvl , type txt) {
00017 set logfile "mylog.log"
00018 set msg "\[[clock format [clock seconds]]\] $txt"
00019 set f [open $logfile {WRONLY CREAT APPEND}] ;# instead of "a"
00020 fconfigure $f -encoding utf-8
00021 puts $f $msg
00022 close $f
00023 }
00024
00025
00026 log = [logger::init global]
00027
00028
00029 foreach lvl [logger::levels] {
00030 interp alias {} log_to_file_$lvl {} log_to_file $lvl
00031 ${log}::logret $lvl log_to_file_$lvl
00032 }
00033
00034 # Send a simple message to the logfile
00035 $(type log)::info "Logging to a file"