This topic contains 4 replies, has 2 voices, and was last updated by  roho 8 years, 5 months ago.

Get logging level in Lua script?

  • Hi guys,

    is there a way to get the logging level of the channel in the Lua code?

    I’d like to spread a lot of logDebug statements all over the Lua code, but I’m worrying that many statements

    iguana.logDebug(<a href="">inspect</a>.inspect(result))

    will slow me down by creating the output even if logDebug is switched off.

    The only thing I found was:

       local xml = xml.parse{data=iguana.channelConfig{name='ChannelName'}}
       local loggingLevel =


    • that doesn’t seem to change when I change the logging level in the control panel of the channel… it only reads the setting from IguanaConfiguration.xml?
    • parsing the XML might be even slower…

    So what I need is either a way to quickly get whether debug logging is enabled, or a logDebug function which accepts a lambda expression, i.e. a function which is then only evaluated if debug log is on.

    Is there any possibility for this?

    Oh that is funny – I saw a notification for your question and implemented this function:

    function LoggingLevel()
    if (not Level) then
    local X = xml.parse{data=iguana.channelConfig{guid=iguana.channelGuid()}}
    Level = tonumber(tostring(
    return Level

    Which is the same type of solution – although it does some caching of the result. The API doesn’t actually hit the disk – it constructs the XML fragment you see from memory so the only impact of this is a little bit of extra CPU usage. On the whole most of the time Iguana tends not to max out CPU – IO (input/output) tends to be where the overhead occurs so I would suspect it won’t make much practical difference if you hit this API every time.

    Although I doubt it matters all that much here is a slightly more sophisticated caching scheme. It keeps the API value for 5 seconds:

    -- 2 means debug level. 1 is normal and 0 is no logging. This function caches the
    -- logging level if found for the last 5 seconds
    local LastTime =0
    local LogLevel

    function LoggingLevel()
    if os.ts.time() - 5 > LastTime then -- Check to see last time we looked this up
    LastTime = os.ts.time()
    local X = xml.parse{data=iguana.channelConfig{guid=iguana.channelGuid()}}
    LogLevel = tonumber(tostring(
    return LogLevel

    It’s a reasonable general solution for looking anything up that doesn’t change often but has some overhead in fetching.

    I have tested the speed of any of these in production – be curious to see what you find if you have time to try it…

    Incidentally it’s a similar optimization we use for some of Iguana’s own internal tracing…enjoy!

    Happy Holidays if I don’t hear from you before the season 🙂

    Hi Eliot,
    OK, so maybe this is indeed the way to go. I think the first solution is good enough, the 5 seconds caching is really really fancy 🙂

    Thanks a lot for your help!

You must be logged in to reply to this topic.