title: Object Oriented Event Logging in Java API Design
body: <p>I want to solve this problem:</p>
  
  <p>Most apps have some logging service for reporting events in the application to a business intelligence analytics database.  Also, mobile apps like android report the same things like user behavior and so on.  There are many libraries to do this. </p>
  
  <p>Problem: When developers want to add logging to their code, it's usually by scattering lines of code that report something inside their methods, for example:</p>
  
  <pre><code>      void doStuff() {
           try {
               doTheThing():
               logger.info("the thing was done", someClientInfoDTO, timestamp, eventid);
              } catch(Throwable woops) {
                  logger.error(woops);
              }
  
             }
  </code></pre>
  
  <p>I see this pattern everywhere in one form or another.  I want to take an object oriented approach to logging so classes can be annotated with their logging behavior.  An eliminate the need for developers to just stick lines of logging code where they feel something important enough to log is happening.</p>
  
  <p>Where my mind is is to rewrite the above code like this:</p>
  
  <pre><code>@Logger("class level logger")
  class StuffDoer {
      @Logger("what to log", whatToDoOnError, etc)
      void doStuff() {
                  doTheThing():
                     }
  }
  </code></pre>
  
  <p>Question: Are there any libraries or existing projects that address the problem.  Does anyone have an example of doing this successfully? I don't want to reinvent the wheel but i've been digging and coming up empty.  Based on the response to this question i may start a github project to do this.</p>
  
  <p>Jake Wharton gets us part way there with timber: <a href="https://github.com/JakeWharton/timber" rel="nofollow">https://github.com/JakeWharton/timber</a> which is a good way for injecting a logging framework, but still results in devs peppering code with calls to it.</p>