Tk Library Source Code

View Ticket
Login
Ticket UUID: 1102131
Title: logger: does not print full service name
Type: Bug Version: None
Submitter: hemanglavana Created on: 2005-01-14 06:50:48
Subsystem: log Assigned To: mic42
Priority: 8 Severity:
Status: Closed Last Modified: 2005-02-12 01:01:47
Resolution: Fixed Closed By: mic42
    Closed on: 2005-02-09 17:05:53
Description:
Hi,

If I create a logger service name called "foo::bar", it
simply prints "foo" in the log message instead of the
full service name. See below:

godel:144> cat foobar.tcl
#!/bin/sh
# \
exec tclsh "$0" ${1+"$@"}


package require logger

namespace eval ::foo {

    namespace export {[a-z]*} ;# export all commands
begining with lower case.
    variable _foo             ;# array containing foo
runtime globals

    set log [logger::init foo]
    logger::import -all -namespace log foo
    log::setlevel notice
    puts "foo level = [log::currentloglevel]"

}

namespace eval ::foo::bar {

    set log [logger::init foo::bar]
    logger::import -all -namespace log foo::bar
    log::setlevel info
    puts "foo::bar level = [log::currentloglevel]"

}

proc ::foo::x args {
    log::warn   "foo::x warn"
    log::debug  "foo::x debug"
}
proc ::foo::bar::y args {
    log::warn   "foo::bar::y warn"
    log::info   "foo::bar::y info"
    log::debug  "foo::bar::y debug"
}

::foo::x
::foo::bar::y

godel:145> tclsh foobar.tcl
foo level = notice
foo::bar level = info
[Fri Jan 14 01:47:04 EST 2005] [foo] [warn] 'foo::x warn'
[Fri Jan 14 01:47:04 EST 2005] [foo] [warn]
'foo::bar::y warn'
[Fri Jan 14 01:47:04 EST 2005] [foo] [info]
'foo::bar::y info'
godel:146> 

I would have expected the above output to be as follows:

[Fri Jan 14 01:47:04 EST 2005] [foo] [warn] 'foo::x warn'
[Fri Jan 14 01:47:04 EST 2005] [foo::bar] [warn]
'foo::bar::y warn'
[Fri Jan 14 01:47:04 EST 2005] [foo::bar] [info]
'foo::bar::y info'

Without full service name, it is difficult to
distinguish/debug as to which module the message is
comming from.

Hemang.
User Comments: mic42 added on 2005-02-12 01:01:47:
Logged In: YES 
user_id=302287

The last change had introduced an (uneccesary) double eval,
removed one, now it works.

hemanglavana added on 2005-02-11 07:09:16:
Logged In: YES 
user_id=81875

Ok, here's one more error with the latest fix:

hlavana-u5:158> tclsh foobar.tcl-v3 
wrong # args: should be "print msg"
    while executing
"::logger::tree::foo::warn foo::x warn"
    invoked from within
"interp eval {} ::logger::tree::foo::warn {foo::x warn}"
    ("uplevel" body line 1)
    invoked from within
"uplevel 1 [linsert $args 0 interp eval {} [list
::logger::tree::foo::warn]]"
    (procedure "log::warn" line 1)
    invoked from within
"log::warn   "foo::x warn""
    (procedure "::foo::x" line 2)
    invoked from within
"::foo::x"
    (file "foobar.tcl-v3" line 33)
hlavana-u5:159> cat foobar.tcl-v3 
#!/bin/sh
# \
exec tclsh "$0" ${1+"$@"}


package require logger

proc print msg {
   set lvl [expr {[info level]-1}]
   set caller "global"
   if {$lvl > 0} {
       set caller [lindex [info level $lvl] 0]
   }
   puts "PRINT: level = $lvl, caller = $caller, msg=$msg"
}
namespace eval ::foo {

    set log [logger::init foo]
    logger::import -all -namespace log foo
    log::setlevel notice

    log::logproc warn  print
    log::logproc info  print
    log::logproc debug print
}

proc ::foo::x args {
    log::warn   "foo::x warn"
    log::debug  "foo::x debug"
}

::foo::x
hlavana-u5:160>  

Note that I am not able to get latest version via anonymous
cvs so e-mail me to verify further fixes.

Hemang.

mic42 added on 2005-02-10 00:05:27:
Logged In: YES 
user_id=302287

Yes, this is correct, as the internal are handled
differently now (one extra layer of indirection, as always
the solution).

I added a uplevel 1 in the fix, and now the callstack looks
nice again.  (fix is in cvs, logger 0.5.3)

Is this callstack an important feature of logger for you? If
yes, please file a RFE, so it either gets documented and
gets part of the public API or an API is created to get the
caller and callstack (excluding logger internals), so you
can depend on it being stable between releases. (currently
this is not tested).

I hope i can keep the current clean callstack behaviour, but
i thought of it as an internal detail, not a public thing. 

Michael

hemanglavana added on 2005-02-09 11:38:12:
Logged In: YES 
user_id=81875

This fix has introduced a side-effect. The uplevel or [info
level] cmd called from a custom logproc is 1 level deeper.
see the following example:

package require logger

proc print args {
   set lvl [expr {[info level]-1}]
   set caller "global"
   if {$lvl > 0} {
       set caller [lindex [info level $lvl] 0]
   }
   puts "PRINT: level = $lvl, caller = $caller, args=$args"
}

namespace eval ::foo {

    set log [logger::init foo]
    logger::import -all -namespace log foo
    log::setlevel notice

    log::logproc warn  print
    log::logproc info  print
    log::logproc debug print
}

proc ::foo::x args {
    log::warn   "foo::x warn"
    log::debug  "foo::x debug"
}

::foo::x

When I execute the above, it used to print:

hlavana-u5:143> tclsh foobar.tcl-v3
PRINT: level = 1, caller = foo::x, args={foo::x warn}
hlavana-u5:144>

However, it now prints the following with logger.tcl in cvs
head:

hlavana-u5:143> tclsh foobar.tcl-v3
PRINT: level = 2, caller = log::warn, args={foo::x warn}
hlavana-u5:144>

The caller proc name is no longer printed as foo::x.

Hemang.

mic42 added on 2005-02-01 01:05:18:
Logged In: YES 
user_id=302287

There is now a fix in CVS for this. 
Basically the info was not passed down the inheritance
chain, which is now working. 

It now works with all combinations of logger::import, even
if -all is not given (which failed in the older fix).

Michael

mic42 added on 2005-01-14 23:45:06:
Logged In: YES 
user_id=302287

I can confirm this and can offer two possible fixes:
1. keep the current interface to logprocs and hack around it
(quite a mess with alias introspection and other uglyness,
but keeps the two parameters logprocs...)
2. Change the interface of the logprocs and give the service
as a parameter to the logging proc.

The second version is much cleaner and better, but breaks
compatibility.

I have to think about, how to do it _right_, perhaps even
introducing an args parameter for future extension (like
format strings or similar things).

Michael