SLF4s and @elidable

50 views
Skip to first unread message

Sciss

unread,
Nov 30, 2011, 11:50:08 AM11/30/11
to scala-user
hi,

does the following make sense?

@elidable(CONFIG) def logConfig( what: String ) { log.info( what )}

def test : Int = {
logConfig( "testin one two" )
666
}

where log is taken from SLF4s.

that is to say, i understand that in SLF4s logging is suppressed according to log-level set. but what i'd like to have is to not even invoke logConfig at all if i decide so with an elide-below level.

as i see it, log.info would call

def info(msg: => String) {
if (slf4jLogger.isInfoEnabled) slf4jLogger.info(msg)
}

so without @elidable i'd have

def test : Int = {
if (slf4jLogger.isInfoEnabled) slf4jLogger.info("testin one two")
666
}

whereas with elidable i would really get

def test : Int = {
666
}

if i wanted, right?

thanks, -sciss-

Sciss

unread,
Dec 2, 2011, 10:45:00 AM12/2/11
to Sciss, scala-user
since no one answered -- my conclusion is it does make sense for performance critical stuff that needs debug logging.

best, -sciss-

Naftoli Gugenheim

unread,
Dec 5, 2011, 2:18:31 AM12/5/11
to Sciss, scala-user
Don't forget call-by-name. I think most scala logging libraries take their message as a =>String. That largely accomplishes what you want, I think.

Sciss

unread,
Dec 5, 2011, 2:20:48 AM12/5/11
to Naftoli Gugenheim, scala-user
i was thinking about this, but came to the conclusion that it doesn't make sense here.

if i have

@elidable def log( what: String ) { println( "LOG: " + what )}

and

def test( i: Int ) = {
log( "found " + i )
i + i
}

when i let scalac eliminate the elidable stuff, the call log( ... ) in test is also removed (as far as i understand, and from what the step debugger tells me), so adding a by-name argument is redundant here, and probably also not preferable performance-wise.

right?

best, -sciss-

Naftoli Gugenheim

unread,
Dec 5, 2011, 2:37:59 AM12/5/11
to Sciss, scala-user
True, but if your log method only evaluates the message if the log level is past the threshold, then eliding is less necessary.
Anyway, do you set log levels at compile time or run time?

Sciss

unread,
Dec 5, 2011, 3:33:38 AM12/5/11
to Naftoli Gugenheim, scala-user
in this particular case, the logging was used for debugging, and i just wanted to switch it on and off. true, if i wanted granularity with log-levels, i'd use a runtime if( ... ) filter and by-name arguments.

best, -sciss-

Simon Ochsenreither

unread,
Dec 5, 2011, 6:58:52 AM12/5/11
to scala...@googlegroups.com, Sciss
Doesn't that mean that every log message basically creates a new class file?

rkuhn

unread,
Dec 5, 2011, 9:45:18 AM12/5/11
to scala...@googlegroups.com, Sciss

Simon Ochsenreither

unread,
Dec 5, 2011, 4:35:18 PM12/5/11
to scala...@googlegroups.com, Sciss
I fear that all these anonymous-class-avoidance strategies will be obsolete with Java 8 again ... quite some API churn, imho.
Reply all
Reply to author
Forward
0 new messages