ó
Ú"wTc           @   s`   d  Z  d g Z d d l Z d d l Z d d l Z d d l Td e f d „  ƒ  YZ e ƒ  Z	 d S(   s9  Logging support for getmail.

The new standard Python libary module logging didn't cut it for me; it doesn't
seem capable of handling some very simple requirements like logging messages of
a certain level to one fd, and other messages of higher levels to a different fd
(i.e. info to stdout, warnings to stderr).
t   LoggeriÿÿÿÿN(   t   *t   _Loggerc           B   s€   e  Z d  Z d „  Z d „  Z e d „ Z d „  Z d „  Z d d „ Z	 d „  Z
 d	 „  Z d
 „  Z d „  Z d „  Z d „  Z RS(   si   Class for logging.  Do not instantiate directly; use Logger() instead,
    to keep this a singleton.
    c         C   s   g  |  _  t |  _ d S(   s   Create a logger.N(   t   handlerst   Falset   newline(   t   self(    (    s7   /usr/lib/python2.7/dist-packages/getmailcore/logging.pyt   __init__   s    	c         C   s   |  S(   N(    (   R   (    (    s7   /usr/lib/python2.7/dist-packages/getmailcore/logging.pyt   __call__   s    c         C   s0   |  j  j i | d 6| d 6t d 6| d 6ƒ d S(   s  Add a handler for logged messages.

        Logged messages of at least level <minlevel> (and at most level
        <maxlevel>, default CRITICAL) will be output to <stream>.

        If no handlers are specified, messages of all levels will be output to
        stdout.
        t   minlevelt   streamR   t   maxlevelN(   R   t   appendt   True(   R   R
   R	   R   (    (    s7   /usr/lib/python2.7/dist-packages/getmailcore/logging.pyt
   addhandler!   s    	c         C   s   g  |  _  d S(   sÃ   Clear the list of handlers.

        There should be a way to remove only one handler from a list.  But that
        would require an easy way for the caller to distinguish between them.
        N(   R   (   R   (    (    s7   /usr/lib/python2.7/dist-packages/getmailcore/logging.pyt   clearhandlers-   s    c         C   s$  x§ |  j  D]œ } | | d k  s
 | | d k r6 q
 n  | d ra | t k ra | d j d ƒ n  | d j | ƒ | d j ƒ  | j d ƒ rœ t | d <q
 t | d <q
 W|  j  s |  j rÜ | t k rÜ t j	 j d ƒ n  t j	 j | ƒ t j	 j ƒ  | j d ƒ rt |  _ q t |  _ n  d S(   s;   Log a message of level <msglevel> containing text <msgtxt>.R	   R   R   R
   s   
N(
   R   t   DEBUGt   writet   flusht   endswithR   R   R   t   syst   stdout(   R   t   msglevelt   msgtxtt   handler(    (    s7   /usr/lib/python2.7/dist-packages/getmailcore/logging.pyt   log5   s$     	s   trace
c         C   sV   t  j ƒ  d } d | t d t j j | t ƒ | t | f } |  j t	 | ƒ d S(   s™   Log a message with level TRACE.

        The message will be prefixed with filename, line number, and function
        name of the calling code.
        iþÿÿÿs   %s [%s:%i] %ss   ()N(
   t	   tracebackt   extract_stackt   FUNCNAMEt   ost   patht   basenamet   FILENAMEt   LINENOR   t   TRACE(   R   t   msgt   trace(    (    s7   /usr/lib/python2.7/dist-packages/getmailcore/logging.pyR$   L   s    
c         C   s   |  j  t | ƒ d S(   s   Log a message with level DEBUG.N(   R   R   (   R   R#   (    (    s7   /usr/lib/python2.7/dist-packages/getmailcore/logging.pyt   debugZ   s    c         C   s   |  j  t | ƒ d S(   s"   Log a message with level MOREINFO.N(   R   t   MOREINFO(   R   R#   (    (    s7   /usr/lib/python2.7/dist-packages/getmailcore/logging.pyt   moreinfo^   s    c         C   s   |  j  t | ƒ d S(   s   Log a message with level INFO.N(   R   t   INFO(   R   R#   (    (    s7   /usr/lib/python2.7/dist-packages/getmailcore/logging.pyt   infob   s    c         C   s   |  j  t | ƒ d S(   s!   Log a message with level WARNING.N(   R   t   WARNING(   R   R#   (    (    s7   /usr/lib/python2.7/dist-packages/getmailcore/logging.pyt   warningf   s    c         C   s   |  j  t | ƒ d S(   s   Log a message with level ERROR.N(   R   t   ERROR(   R   R#   (    (    s7   /usr/lib/python2.7/dist-packages/getmailcore/logging.pyt   errorj   s    c         C   s   |  j  t | ƒ d S(   s"   Log a message with level CRITICAL.N(   R   t   CRITICAL(   R   R#   (    (    s7   /usr/lib/python2.7/dist-packages/getmailcore/logging.pyt   criticaln   s    (   t   __name__t
   __module__t   __doc__R   R   R.   R   R   R   R$   R%   R'   R)   R+   R-   R/   (    (    (    s7   /usr/lib/python2.7/dist-packages/getmailcore/logging.pyR      s   									(
   R2   t   __all__R   t   os.pathR   R   t   getmailcore.constantst   objectR   R    (    (    (    s7   /usr/lib/python2.7/dist-packages/getmailcore/logging.pyt   <module>   s   	
]