title: Print timestamp for logging in Python
body: <p>I want to print the current timestamp, when an event succeeded or not in my python script.
  By only adding...</p>
  
  <pre><code>datetime.datetime.now().strftime("%d.%b %Y %H:%M:%S")
  </code></pre>
  
  <p>.... at the beginning of each line, te same date appears in every line</p>
  
  <pre><code>[INFO] 04.Feb 2015 20:49:41: cl1
  [ OK ] 04.Feb 2015 20:49:41: 8.8.8.8 ONLINE!
  [INFO] 04.Feb 2015 20:49:41: cl2
  [ OK ] 04.Feb 2015 20:49:41: 8.8.8.8 ONLINE!
  [INFO] 04.Feb 2015 20:49:41: cl3
  [ OK ] 04.Feb 2015 20:49:41: 8.8.8.8 ONLINE!
  </code></pre>
  
  <p>(I added <code>time.sleep(5)</code>in between)</p>
  
  <p>My next idea was to create a function, calling the current time, but i'm failing at embedding this function to the <code>print</code>command.</p>
  
  <blockquote>
    <p>File rs.py</p>
  </blockquote>
  
  <pre><code>OK =   "[" + bc.OKGREEN + " OK "  + bc.ENDC + "] " + datetime.datetime.now().strftime("%d.%b %Y %H:%M:%S")
  INFO = "[" + bc.OKBLUE  + "INFO"  + bc.ENDC + "] " + datetime.datetime.now().strftime("%d.%b %Y %H:%M:%S")
  WARN = "[" + bc.WARN    + "WARN"  + bc.ENDC + "] " + datetime.datetime.now().strftime("%d.%b %Y %H:%M:%S")
  ERR =  "[" + bc.ERR     + "FAIL"  + bc.ENDC + "] " + datetime.datetime.now().strftime("%d.%b %Y %H:%M:%S")
  DEB =  "[" + bc.HEADER  + "DEBUG" + bc.ENDC + "] " + datetime.datetime.now().strftime("%d.%b %Y %H:%M:%S")
  </code></pre>
  
  <blockquote>
    <p>File myapp.py</p>
  </blockquote>
  
  <pre><code>import rs # importing rs.py
  
  print rs.OK + hostname + "is up!"
  time.sleep(3)
  print rs.ERR+ hostname + "is down!"
  </code></pre>
  
  <p>Is printing:</p>
  
  <pre><code>&gt;&gt;&gt; [INFO] 04.Feb 2015 20:49:41: xxx is up!
  &gt;&gt;&gt; [ERR ] 04.Feb 2015 20:49:41: xxx is down!
  </code></pre>