logging in scala

Posted by IttayD on Stack Overflow See other posts from Stack Overflow or by IttayD
Published on 2010-01-07T06:03:22Z Indexed on 2010/04/17 4:33 UTC
Read the original article Hit count: 294

Filed under:
|

In Java, the standard idiom for logging is to create a static variable for a logger object and use that in the various methods.

In Scala, it looks like the idiom is to create a Logging trait with a logger member and mixin the trait in concrete classes. This means that each time an object is created it calls the logging framework to get a logger and also the object is bigger due to the additional reference.

Is there an alternative that allows the ease of use of "with Logging" while still using a per-class logger instance?

EDIT: My question is not about how one can write a logging framework in Scala, but rather how to use an existing one (log4j) without incurring an overhead of performance (getting a reference for each instance) or code complexity. Also, yes, I want to use log4j, simply because I'll use 3rd party libraries written in Java that are likely to use log4j.

© Stack Overflow or respective owner

Related posts about scala

Related posts about logging