ó
Bü½cc           @   sw   d  Z  d d l Z d d l Z d d l Z d d l m Z d d l m Z d d l m	 Z	 d Z
 d d	 d „  ƒ  YZ d S(
   sD   File-based logger, writes to named category files in mm_cfg.LOG_DIR.iÿÿÿÿN(   t
   StringType(   t   mm_cfg(   t   _logexcs
   iso-8859-1t   Loggerc           B   sV   e  Z d  d d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d	 „  Z	 RS(
   i   i    c         C   sY   t  j j t j | ƒ |  _ d |  _ | |  _ t	 p< t
 j ƒ  |  _ | rU |  j ƒ  n  d S(   s{  nofail says to fallback to sys.__stderr__ if write fails to
        category file - a complaint message is emitted, but no exception is
        raised.  Set nofail=0 if you want to handle the error in your code,
        instead.

        immediate=1 says to create the log file on instantiation.
        Otherwise, the file is created only when there are writes pending.
        N(   t   ost   patht   joinR   t   LOG_DIRt   _Logger__filenamet   Nonet   _Logger__fpt   _Logger__nofailt   LOG_ENCODINGt   syst   getdefaultencodingt   _Logger__encodingt   _Logger__get_f(   t   selft   categoryt   nofailt	   immediate(    (    s5   /export/web/mailman/mailman/Mailman/Logging/Logger.pyt   __init__$   s    			c         C   s   |  j  ƒ  d  S(   N(   t   close(   R   (    (    s5   /export/web/mailman/mailman/Mailman/Logging/Logger.pyt   __del__4   s    c         C   s   d |  j  j |  j f S(   Ns
   <%s to %s>(   t	   __class__t   __name__R   (   R   (    (    s5   /export/web/mailman/mailman/Mailman/Logging/Logger.pyt   __repr__7   s    c         C   sÙ   |  j  r |  j  Sy t j d ƒ } z[ y% t j |  j d |  j d d ƒ } Wn& t k
 rr t |  j d d ƒ } n X| |  _  Wd  t j | ƒ XWn? t k
 rÐ } |  j	 rÊ t
 |  | ƒ t j } |  _  qÑ ‚  n X| Sd  S(   Ni   s   a+t   replacei   (   R
   R   t   umaskt   codecst   openR   R   t   LookupErrort   IOErrorR   R   R   t
   __stderr__(   R   t   out   ft   e(    (    s5   /export/web/mailman/mailman/Mailman/Logging/Logger.pyt   __get_f:   s&    		c         C   s,   |  j  ƒ  } t | d ƒ r( | j ƒ  n  d  S(   Nt   flush(   R   t   hasattrR&   (   R   R#   (    (    s5   /export/web/mailman/mailman/Mailman/Logging/Logger.pyR&   R   s    c         C   sk   t  | t ƒ r' t | |  j d ƒ } n  |  j ƒ  } y | j | ƒ Wn  t k
 rf } t |  | ƒ n Xd  S(   NR   (   t
   isinstanceR    t   unicodeR   R   t   writeR    R   (   R   t   msgR#   (    (    s5   /export/web/mailman/mailman/Mailman/Logging/Logger.pyR*   W   s    c         C   s"   x | D] } |  j  | ƒ q Wd  S(   N(   R*   (   R   t   linest   l(    (    s5   /export/web/mailman/mailman/Mailman/Logging/Logger.pyt
   writelines`   s    c         C   s*   |  j  s d  S|  j ƒ  j ƒ  d  |  _  d  S(   N(   R
   R   R   R	   (   R   (    (    s5   /export/web/mailman/mailman/Mailman/Logging/Logger.pyR   d   s    	(
   R   t
   __module__R   R   R   R   R&   R*   R.   R   (    (    (    s5   /export/web/mailman/mailman/Mailman/Logging/Logger.pyR   #   s   							(    (   t   __doc__R   R   R   t   typesR    t   MailmanR   t   Mailman.Logging.UtilsR   R   R   (    (    (    s5   /export/web/mailman/mailman/Mailman/Logging/Logger.pyt   <module>   s   