简体   繁体   中英

Tcl logger package - bug when inheriting logproc

Consider the following code:

package require logger
proc mylog {msg} {
    puts "mylog: $msg"
}
set p [logger::init parent]
set c [logger::init parent::child]
${p}::logproc error mylog
${p}::error "from parent"
${c}::error "from child"

Resulting output:

mylog: from parent
mylog: -_logger::service parent::child {from child}

So, changing logproc for a parent kinda propagates to a child logger, but produces a bug. I can workaround the issue by setting the logproc for the child explicitly. Is it a genuine bug or am I overlooking something? I believed, this was the standard Tcl package for logging. Should I drop this package altogether and switch to something else?

Using tcllib's logger package in version 0.9.4 (most current), I can reproduce the inflated argument passed to your custom proc mylog . The two-arguments form of the logproc does not provide for massaging (internally) the arguments list before passing it down to your proc in case of "inheritance".

One immediate option for you: Use the old, three-arguments form of logproc :

${p}::logproc error msg {
  puts "mylog: $msg"
}

I believed, this was the standard Tcl package for logging.

It comes with tcllib and is maintained actively, yes, but I would not call it "standard". If it was, it would be in Tcl core. But there is no logging utility in Tcl core, so there is no standard, simply.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM