TCL::Proc 来自另一个 Proc 的名称

TCL::Proc Name From another Proc

我想拼写出tcl中的proc名称,以构建更强大的tcl程序。我在 Whosebug 中经历了一些问题,它们谈论的是相同的,我从中构建了以下内容 -

proc logInfo { {type DEBUG} {msg "This is a debug statement"} } {

set timeStampLog [clock format [clock seconds] -format "%m/%d/%y::%H:%M:%S"]

puts "${timeStampLog}::'[lindex [info level [info level]] 0]'::$type - $msg"

}


proc test { } {

logInfo Warning "This is a test proc only"

}

我希望 proc 在调用时显示以下内容 -

tclsh> test
08/05/15::09:41:48::'test'::Warning - This is a test proc only
tclsh>

这是我看到的 -

tclsh> test
08/05/15::09:41:48::'logInfo'::Warning - This is a test proc only
tclsh>

有没有办法指向当前的 proc 名称?

谢谢

“当前”有时是一个棘手的概念,因为当您 运行 logInfo 时,它确实是当前程序。您想要当前过程的调用者;使用 info level -1 代替 info level [info level](正数从堆栈底部开始计数,零和负数从堆栈末端开始计数)。

这实际上稍微简化了您的代码。

proc logInfo { {type DEBUG} {msg "This is a debug statement"} } {
    set timeStampLog [clock format [clock seconds] -format "%m/%d/%y::%H:%M:%S"]
    puts "${timeStampLog}::'[lindex [info level -1] 0]'::$type - $msg"
}