ó
ë–+[c           @   s¨   d  Z  d d l Z d d l Z d d l Z y$ d d l m Z d d l m Z Wn1 e k
 r d d l m Z d d l m Z n Xd Z
 d e j ƒ  f d „  ƒ  YZ d S(   sJ  
.. module:: PipeLogger
   :synopsis: base logger customization for the analysis pipeline
.. versionadded:: 3.0.0
.. versionchanged:: 3.0.0

This is a logger for the pipeline that extends the default Python logger class

Copyright (c) 2016-2017, Evgeny Zdobnov (ez@ezlab.org)
Licensed under the MIT license. See LICENSE.md file.

iÿÿÿÿN(   t   NoOptionError(   t   NoSectionErrort
   PipeLoggerc           B   sŒ   e  Z d  Z e j Z e Z e d d „ ƒ Z
 d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z e d „  ƒ Z e d	 „  ƒ Z d
 „  Z RS(   s1   
    This class customizes the _logger class
    c         C   s   yR | r* | j  d d ƒ r* t j t _ n' | rQ | j  d d ƒ rQ t j t _ n  Wn! t k
 re n t k
 ru n Xt j t ƒ t j	 |  ƒ S(   s!  
        :param name: the name of the logger to be returned
        :type name: str
        :param config: the parameters of the analysis
        :type config: PipeConfig
        :return: a PipeLogger, new or existing, corresponding to the provided name
        :rtype: PipeLogger
        t   buscot   quiett   debug(
   t
   getbooleant   loggingt   ERRORR   t   _levelt   DEBUGR    R   t   setLoggerClasst	   getLogger(   t   namet   config(    (    sT   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/busco/pipebricks/PipeLogger.pyt
   get_logger&   s    
c         C   s™   t  t |  ƒ j | ƒ |  j t j ƒ t j d ƒ |  _ t j d ƒ |  _ t	 r] |  j
 ƒ  n8 t j t j ƒ |  _ |  j j |  j ƒ |  j |  j ƒ d S(   sh   
        :param name: the name of the PipeLogger instance to be created
        :type name: str
        s   %(levelname)s	%(message)ss(   %(levelname)s:%(threadName)s	%(message)sN(   t   superR   t   __init__t   setLevelR	   R   t	   Formattert
   _formattert   _thread_formattert   run_dirpatht
   reload_logt   StreamHandlert   syst   stdoutt	   _out_hdlrt   setFormattert
   addHandler(   t   selfR   (    (    sT   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/busco/pipebricks/PipeLogger.pyR   =   s    c         C   sa   t  d } x |  j D] } |  j | ƒ q Wt j | d d ƒ} | j t j ƒ |  j | ƒ d  S(   Ns   .logt   modet   w(   R   t   handlerst   removeHandlerR   t   FileHandlerR   R
   R   (   R   t
   _log_fpatht   handlert   file_handler(    (    sT   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/busco/pipebricks/PipeLogger.pyR   O   s    
c         C   s   |  j  j |  j ƒ d S(   su   
        This function appends the thread name to the logs output,
        e.g. INFO:Analysis.py:thread_name
        N(   R   R   R   (   R   (    (    sT   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/busco/pipebricks/PipeLogger.pyt   add_thread_infoW   s    c         C   s   |  j  j |  j ƒ d S(   sj   
        This function disables the thread name in the logs output,
        e.g. INFO:Analysis.py
        N(   R   R   R   (   R   (    (    sT   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/busco/pipebricks/PipeLogger.pyt   remove_thread_info^   s    c         O   s   |  j  | | | Ž d S(   s~   
        This function overrides the _logger class warn
        :param msg: the message to log
        :type msg: str
        N(   t   warning(   R   t   msgt   argst   kwargs(    (    sT   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/busco/pipebricks/PipeLogger.pyt   warnf   s    c         O   s)   t  t _ t t |  ƒ j | | | Ž d S(   s   
        This function overrides the _logger class warning
        :param msg: the message to log
        :type msg: str
        N(   t   TrueR   t   _has_warningR   R)   (   R   R*   R+   R,   (    (    sT   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/busco/pipebricks/PipeLogger.pyR)   o   s    	c           C   s   t  j S(   sW   
        :return: whether any _logger did log warnings
        :rtype: boolean
        (   R   R/   (    (    (    sT   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/busco/pipebricks/PipeLogger.pyt   has_warningx   s    c           C   s   t  t _ d S(   sE   
        Reset the has warning flag to False for all _logger
        N(   t   FalseR   R/   (    (    (    sT   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/busco/pipebricks/PipeLogger.pyt   reset_warning€   s    c         O   s0   | d k r, |  j  d | | f | | Ž n  d S(   sß   
        This function logs an info line mentioning this is an external tool
        :param tool: the name of the tool
        :type tool: str
        :param msg: the message
        :type msg: str
        :return:
        t    s   [%s]	%sN(   t   info(   R   t   toolR*   R+   R,   (    (    sT   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/busco/pipebricks/PipeLogger.pyt   info_external_tool‡   s    	N(   t   __name__t
   __module__t   __doc__R   t   INFOR	   R1   R/   t   staticmethodt   NoneR   R   R   R'   R(   R-   R)   R0   R2   R6   (    (    (    sT   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/busco/pipebricks/PipeLogger.pyR      s   									(   R9   R   R   t   ost   configparserR    R   t   ImportErrort   ConfigParserR<   R   t   getLoggerClassR   (    (    (    sT   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/busco/pipebricks/PipeLogger.pyt   <module>   s   