如何在tcl中使用trace命令编写日志消息?

时间:2018-03-14 16:56:35

标签: tcl

所以我有这些示例代码:

package require logger
set logger [logger::init someservice]
proc second {} {}
proc first {} {second}
${logger}::trace on
${logger}::trace add first second
puts "monitored procesured are: [${logger}::trace status]"
first
${logger}::delete

运行代码后得到以下结果:

[Wed Mar 14 11:44:11 EDT 2018] [someservice] [trace] 'enter {proc ::first 
level 1 script {} caller {} procargs {}}'
[Wed Mar 14 11:44:11 EDT 2018] [someservice] [trace] 'enter {proc ::second 
level 2 script {} caller ::first procargs {}}'
[Wed Mar 14 11:44:11 EDT 2018] [someservice] [trace] 'leave {proc ::second 
level 2 script {} caller ::first status ok result {}}'
[Wed Mar 14 11:44:11 EDT 2018] [someservice] [trace] 'leave {proc ::first 
level 1 script {} caller {} status ok result {}}'

我试图找出如何使用logger通过设置文件处理程序将结果写入文本文件。我试着把" $ {:: filehandler}"在代码中间,但它只打印出#34;第一个"在文本文件中。我应该如何键入命令以在另一个日志文件中打印出工作进程?

1 个答案:

答案 0 :(得分:0)

查阅logger文档,尤其是关于logproc的部分:

proc log2file {lvl txt} { 
   # handle output to file handle
}

set log [::logger::init example]
${log}::logproc trace log2file