Home
Reading
Searching
Subscribe
Sponsors
Statistics
Posting
Contact
Spam
Lists
Links
About
Hosting
Filtering
Features Download
Marketing
Archives
FAQ
Blog
 
Gmane

From: Ittay Dror <ittay.dror-Re5JQEeQqe8AvxtiuMwx3w <at> public.gmane.org>
Subject: verbose logger usage
Newsgroups: gmane.comp.lang.scala.user
Date: Sunday 12th December 2010 09:24:07 UTC (over 8 years ago)
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
 
CD: 14ms