lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


I have a little logging class where I use debug.getinfo() to build the context of a log call, e.g. the package and function name which invoked the log method.

For example, assuming an 'Example.lua' main chunk with the following log statements:

Log.debug( aDBMap.get( "DEC" ) )
Log.debug( aDBMap.hasKey( "DEC" ) )

Produces this output:

03/05 10:54:56 (Debug) Example.main: "December"
03/05 10:54:56 (Debug) Example.main: true

All in all, this work quite nicely. However, from time to time, debug.getinfo() seems to get confused. For example, the call after the ones above:

Log.debug( aDBMap.hasValue( "December" ) )

Produces the following output:

03/05 10:54:56 (Debug) Example.DEC: true

Note the "DEC" value for the function name, instead of "main" as for every other calls. How come? What is "DEC" doing there? "DEC" is the key for that value, but it shouldn't have anything to do with debug.getinfo(), isn't it? This is not critical, as it seldomly happen, but still, what would explain such confusion?

The relevant implementation of Log goes something like this:

        if ( ( aClassName == nil ) or ( aMethodName == nil ) ) then
                local someInfo = debug.getinfo( 3, "Sn" )

                if ( aClassName == nil ) then
aClassName = LUBundle.nameWithPath( someInfo.source )

                if ( aMethodName == nil ) then
                        aMethodName =

                        if ( aMethodName == nil ) then
                                aMethodName = someInfo.what

Full source code available here:

Any insights appreciated. Thanks!


PA, Onnay Equitursay