groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paolo Di Tommaso <paolo.ditomm...@gmail.com>
Subject @Slf4j transformation does not check level guard
Date Fri, 29 Jan 2016 17:07:13 GMT
Dear all,

I've noticed that a logger defined with a @Slf4j transformation does check
the *implicit* trace level guard as expected.

For example the following code report an error for the `foo` method.

@groovy.util.logging.Slf4j
class TestLog {
  def bar () {
    int count=0
    if( log.isTraceEnabled() )  {
        log.trace "${count++}"
    }
    return count
  }

  def foo () {
    int count=0
    log.trace "${count++}"
    return count
  }

}

assert new TestLog().bar() == 0
assert new TestLog().foo() == 0

Assertion failed:
assert new TestLog().foo() == 0
       |             |     |
       |             1     false
       TestLog@416b8a53



Even more strangely, checking the code generated by Slf4j transformation
using the groovy console I can see that the "log.trace" line is correctly
replaced by the code:

log.isTraceEnabled() ? log.trace("$(count++)") : null



This really confuse me. Any clue what's wrong?


Cheers,
Paolo

Mime
View raw message