我正在寻找一些Tcl代码,它会复制puts命令发送到某个日志文件的stdout。是的,可以改变所有呼叫以放入某个自定义功能。但我希望尽可能透明。 我有这样的试验代码,但它并没有真正的工作都顺利:示例代码使put日志输出
set pass_log_output "0"
rename puts _puts
proc puts { args } {
global pass_log_output
if {[info exists pass_log_output]} {
# There can be several cases:
# -nonewline parameter, stdout specified or not
set stdout_dest [ lsearch $args stdout ]
set nonewline [ lsearch $args -nonewline ]
if { $stdout_dest != -1 } {
log_low_level "" [lindex $args [expr $stdout_dest + 1]] ""
} elseif { $nonewline != -1 && [ llength $args ] > 1} {
log_low_level "" [lindex $args [expr $nonewline + 1]] ""
} else {
log_low_level "" [lindex $args 0] ""
}
}
if { [ catch { eval _puts $args } err ] } {
return -code error $err
}
}
log_low_level功能只是存储在文件传递的字符串。 到目前为止,我得到这个错误:
Tcl Interpreter Error: too many nested evaluations (infinite loop?)
就是这样,这就是问题所在。谢谢。 – user1476056 2012-07-25 18:13:00