title: How to write own logging methods for own logging levels
body: <p>Hi<br>
  I would like to extend my logger (taken by logging.getLogger("rrcheck")) with my own methods like: 
  <code>def warnpfx(...):
  </code></p>
  
  <p>How to do it best?  </p>
  
  <p>My original wish is to have a root logger writing <strong>everything</strong> to a file and additionally named logger ("rrcheck") writing to stdout, but the latter should also have some other methods and levels. I need it to prepend some messages with "! PFXWRN" prefix (but only those going to stdout) and to leave other messages unchanged. I would like also to set logging level <strong>separately</strong> for root and for named logger.  </p>
  
  <p>This is my code:</p>
  
  <pre><code>class CheloExtendedLogger(logging.Logger):
      """
      Custom logger class with additional levels and methods
      """
      WARNPFX = logging.WARNING+1
  
      def __init__(self, name):
          logging.Logger.__init__(self, name, logging.DEBUG)                
  
          logging.addLevelName(self.WARNPFX, 'WARNING')
  
          console = logging.StreamHandler()
          console.setLevel(logging.DEBUG)
          # create formatter and add it to the handlers
          formatter = logging.Formatter("%(asctime)s [%(funcName)s: %(filename)s,%(lineno)d] %(message)s")
          console.setFormatter(formatter)
  
          # add the handlers to logger
          self.addHandler(console)
  
          return
  
      def warnpfx(self, msg, *args, **kw):
          self.log(self.WARNPFX, "! PFXWRN %s" % msg, *args, **kw)
  
  
  logging.setLoggerClass(CheloExtendedLogger)    
  rrclogger = logging.getLogger("rrcheck")
  rrclogger.setLevel(logging.INFO)
  
  def test():
      rrclogger.debug("DEBUG message")
      rrclogger.info("INFO message")
      rrclogger.warnpfx("warning with prefix")
  
  test()
  </code></pre>
  
  <p>And this is an output - function and lilne number is wrong: <em>warnpfx</em> instead of <em>test</em></p>
  
  <pre><code>2011-02-10 14:36:51,482 [test: log4.py,35] INFO message
  2011-02-10 14:36:51,497 [warnpfx: log4.py,26] ! PFXWRN warning with prefix
  </code></pre>
  
  <p>Maybe my own logger approach is not the best one?<br>
  Which direction would you propose to go (own logger, own handler, own formatter, etc.)?</p>
  
  <p>How to proceed if I would like to have yet another logger?<br>
  Unfortunatelly logging has no possibility to register an own logger, so then getLogger(name) would take a required one...</p>
  
  <p>Regards,<br>
  Zbigniew</p>