I want to use log module from tcllib to log to console and a file. Here's some working code to redirect the log output to a file.
tcl;
package require logger;
package require logger::utils;
global log;
set log [logger::init Main];
set progName "Main"
set progVersion "1.0"
set workDir "C:/Temp/$progName"
set timestamp [clock format [clock seconds] -format "%Y%m%d_%H%M%S"]
if { [file isdirectory $workDir] == 0 } {
file mkdir "$workDir"
}
set outputFilePath "$workDir/${progName}_$timestamp.txt"
set outputFile [ open "$outputFilePath" "w" ]
logger::utils::applyAppender \
-appender fileAppend \
-appenderArgs "-outputChannel $outputFile" \
-serviceCmd $log
if {[catch {
${log}::debug "debug log"
${log}::info "info log"
} err ]} {
${log}::critical "$err"
}
${log}::delete
This is the console output from the above script...
0.9.4
1.3.1
::logger::tree::Main
Main
1.0
C:/Temp/Main
20190830_175510
C:/Temp/Main/Main_20190830_175510.txt
file74067dc0
The content of C:/Temp/Main/Main_20190830_175510.txt is...
[2019/08/30 17:54:08] [Main] [global] [debug] debug log
[2019/08/30 17:54:08] [Main] [global] [info] info log
When I add another logger the output is no longer redirected to the file, but only to console
logger::utils::applyAppender \
-appender console \
-serviceCmd $log
How can I initialize the logging that the logs are sent to console and the file?