title: Python 3: How to log warnings and errors to log file?
body: <p>Say I have a <code>While</code> loop that runs forever(it does system monitoring).</p>
  
  <p>It has three conditions,</p>
  
  <pre><code>While True:
  
      if something1
          Everything is OK!
      if something2
          Warning
      if something3
          Error
  </code></pre>
  
  <p>The first, I don't want anything for. The second, I'd like to add a warning to a logfile. For the third, the same - except it's an error.</p>
  
  <p>Since these are in a while loop, can I still just add a logger to something2 and something3? Do I start out with the below?</p>
  
  <p><code>import logging
  logger = logging.getLogger()
  </code></p>
  
  <p>But how do I add warning and error to each respective if statement so it writes to the same logfile?</p>