title: Should I log before or after an operation?
body: <p>I'm thinking about where to write the log record around an operation. Here are two different styles. The first one, write log before the operation.</p>
  
  <p>Before:</p>
  
  <pre><code>log.info("Perform operation XXX")
  operation()
  </code></pre>
  
  <p>And here is a different style, write the log after the operation.</p>
  
  <p>After:</p>
  
  <pre><code>operation()
  log.info("Operation XXX is done.")
  </code></pre>
  
  <p>With the before-style, the logging records say what is going to do now. The pro of this style is that when something goes wrong, developer can detect it easily, because they know what is the program doing now.  But the con is that you are not sure is the operation finished correctly, if something wrong is inside the operation, for example, a function call gets blocked there and never return, you can't never know it by reading the logging records.  With the after-style, you are sure the operation is done.</p>
  
  <p>Of course, we can mix those two style together</p>
  
  <p>Both:</p>
  
  <pre><code>log.info("Perform operation XXX")
  operation()
  log.info("Operation XXX is done.")
  </code></pre>
  
  <p>But I feel that is kinda verbose, it makes double logging records.  So, here is my question - what is the good logging style?  I would like to know how do you think.</p>