Hi All,
Something that has bothered me since starting to use Scala is how to use
logging.
In Java the standard way is of course:
class Foo {
private static final Logger log =
Logger.getLogger(com.example.package.Foo.class);
public void example {log.info("this is an example");}
}
In Scala, the straight forward way is:
class Foo {
def example = Foo.log.info("this is an example")
}
object Foo {
val log = Logger.getLogger(classOf[Foo])
}
Without counting character-by-character, the Scala version looks more
verbose.
Alternatively, I can create a Logging trait
trait Logging {
lazy val log = Logger.getLogger(this.getClass)
}
But then I'd have a Logger instance in every object
What are the alternatives to get both short code and small memory
footprint?
Regards,
Ittay