§
    d¤#  ã                   óŠ   — d Z ddlZddlZddlZddlZddlZddlZddlZdadd„Z	dd„Z
d„ Zdd	„Z G d
„ dej        ¦  «        ZdS )a  logging facilities

The way to use this is as follows:

* each module declares its own logger, using:

    from .logger import create_logger
    logger = create_logger()

* then each module uses logger.info/warning/debug/etc according to the
  level it believes is appropriate:

    logger.debug('debugging info for developers or power users')
    logger.info('normal, informational output')
    logger.warning('warn about a non-fatal error or sth else')
    logger.error('a fatal error')

  ... and so on. see the `logging documentation
  <https://docs.python.org/3/howto/logging.html#when-to-use-logging>`_
  for more information

* console interaction happens on stderr, that includes interactive
  reporting functions like `help`, `info` and `list`

* ...except ``input()`` is special, because we can't control the
  stream it is using, unfortunately. we assume that it won't clutter
  stdout, because interaction would be broken then anyways

* what is output on INFO level is additionally controlled by commandline
  flags
é    NFc                 ó|   — |› d|› d|j         › d| › �}t          t           ¦  «        }|                     |¦  «         d S )Nú:z: )Ú__name__Úcreate_loggerÚwarning)ÚmessageÚcategoryÚfilenameÚlinenoÚfileÚlineÚmsgÚloggers           ú-/usr/lib/python3/dist-packages/borg/logger.pyÚ_log_warningr   /   sO   € àÐ
@Ð
@˜Ð
@Ð
@ (Ô"3Ð
@Ð
@°wÐ
@Ð
@€CÝ�8Ñ$Ô$€Fð ‡N‚N�3ÑÔÐÐÐó    ÚBORG_LOGGING_CONFÚinfoc                 ó
  — d}|r t           j                             ||¦  «        }|rî	 t           j                             |¦  «        }t          |¦  «        5 }t          j                             |¦  «         ddd¦  «         n# 1 swxY w Y   da	t          j
        t          ¦  «        }t          j
        d¦  «        }	||	_        |                     d|› d�¦  «         t          t          _        dS # t"          $ r}
t%          |
¦  «        }Y d}
~
nd}
~
ww xY wt          j
        d¦  «        }t          j        | ¦  «        }|r|sd}nd}|rt)          |¦  «        nt          j        |¦  «        }|                     |¦  «         t          j
        d¦  «        }	||	_        ||	_        t          r?|j        r8|j        d	                              ¦   «          |j                             ¦   «          |                     |¦  «         |                     |                     ¦   «         ¦  «         da	t          j
        t          ¦  «        }|r|                     d
|› d|› d�¦  «         |                     d¦  «         t          t          _        |S )a¢  setup logging module according to the arguments provided

    if conf_fname is given (or the config file name can be determined via
    the env_var, if given): load this logging configuration.

    otherwise, set up a stream handler logger on stderr (by default, if no
    stream is provided).

    if is_serve == True, we configure a special log format as expected by
    the borg client log message interceptor.
    NTÚborgz'using logging configuration read from "ú"Ú z/$LOG %(levelname)s %(name)s Remote: %(message)sz%(message)sr   zsetup_logging for "z" failed with "z".z,using builtin fallback logging configuration)ÚosÚenvironÚgetÚpathÚabspathÚopenÚloggingÚconfigÚ
fileConfigÚ
configuredÚ	getLoggerr   ÚjsonÚdebugr   ÚwarningsÚshowwarningÚ	ExceptionÚstrÚStreamHandlerÚJsonFormatterÚ	FormatterÚsetFormatterÚ	formatterÚhandlersÚcloseÚclearÚ
addHandlerÚsetLevelÚupperr   )ÚstreamÚ
conf_fnameÚenv_varÚlevelÚis_server$   Úerr_msgÚfr   Úborg_loggerÚerrÚhandlerÚfmtr.   s                 r   Úsetup_loggingr@   8   s¯  € ð €GØð 9Ý”Z—^’^ G¨ZÑ8Ô8ˆ
Øð ð	ÝœŸš¨Ñ4Ô4ˆJõ
 �jÑ!Ô!ð - QÝ”×)Ò)¨!Ñ,Ô,Ð,ð-ð -ð -ñ -ô -ð -ð -ð -ð -ð -ð -øøøð -ð -ð -ð -àˆJÝÔ&¥xÑ0Ô0ˆFÝ!Ô+¨FÑ3Ô3ˆKØ#ˆKÔØ�LŠLÐPÀ:ÐPÐPÐPÑQÔQÐQÝ#/�HÔ Ø�4øÝð 	ð 	ð 	Ý˜#‘h”hˆGˆGˆGˆGˆGˆGøøøøð	øøøõ Ô˜rÑ"Ô"€FÝÔ# FÑ+Ô+€GØð ˜ð Ø?ˆˆàˆØ&*ÐF•˜cÑ"Ô"Ð"µÔ0AÀ#Ñ0FÔ0F€IØ×Ò˜Ñ#Ô#Ð#ÝÔ# FÑ+Ô+€KØ%€KÔØ€KÔÝð  �f”oð  ð 	Œ˜Ô× Ò Ñ"Ô"Ð"ØŒ×ÒÑÔÐØ
×Ò�gÑÔÐØ
‡O‚O�E—K’K‘M”MÑ"Ô"Ð"Ø€JÝÔ�xÑ(Ô(€FØð UØ�ŠÐS¨ZÐSÐSÈÐSÐSÐSÑTÔTÐTØ
‡L‚LÐ?Ñ@Ô@Ð@Ý'…HÔØ€Ns<   ¨.C/ Á BÁ6C/ ÂBÂC/ Â	BÂ
A#C/ Ã/
DÃ9DÄDc                  ó  — 	 t          j        ¦   «         j        } t          j        | ¦  «        }|�|j        t          k    r-| j        } t          j        | ¦  «        }|®|j        t          k    °-|j        S # t
          $ r
 t          cY S w xY w)z‘find the name of the first module calling this module

    if we cannot find it, we return the current module's name
    (__name__) instead.
    )ÚinspectÚcurrentframeÚf_backÚ	getmoduler   ÚAttributeError)ÚframeÚmodules     r   Úfind_parent_modulerI   w   s“   € ð
ÝÔ$Ñ&Ô&Ô-ˆÝÔ" 5Ñ)Ô)ˆØˆn ¤µ8Ò ;Ð ;Ø”LˆEÝÔ& uÑ-Ô-ˆFð ˆn ¤µ8Ò ;Ð ;ð ŒÐøÝð ð ð õ ˆˆˆðøøøs   ‚A1A4 Á4BÂBc                 ó8   ‡—  G ˆfd„d¦  «        Š ‰| ¦  «        S )a…  lazily create a Logger object with the proper path, which is returned by
    find_parent_module() by default, or is provided via the commandline

    this is really a shortcut for:

        logger = logging.getLogger(__name__)

    we use it to avoid errors and provide a more standard API.

    We must create the logger lazily, because this is usually called from
    module level (and thus executed at import time - BEFORE setup_logging()
    was called). By doing it lazily we can do the setup first, we just have to
    be careful not to call any logger methods before the setup_logging() call.
    If you try, you'll get an exception.
    c                   óh   •— e Zd Zdd„Zed„ ¦   «         Zˆ fd„Zd„ Zd„ Zd„ Z	d„ Z
d	„ Zd
„ Zd„ Zd„ ZdS )ú!create_logger.<locals>.LazyLoggerNc                 ó>   — |pt          ¦   «         | _        d | _        d S ©N)rI   Ú_LazyLogger__nameÚ_LazyLogger__real_logger)ÚselfÚnames     r   Ú__init__z*create_logger.<locals>.LazyLogger.__init__›   s#   € ØÐ6Õ"4Ñ"6Ô"6ˆDŒKØ!%ˆDÔÐÐr   c                 ó"  — | j         €‚t          st          d¦  «        ‚t          j        | j        ¦  «        | _         | j                             d¦  «        r4| j         j        t          j        k    r| j          	                    d¦  «         | j         S )Nz8tried to call a logger before setup_logging() was calledzborg.debug.ÚWARNING)
rP   r"   r(   r   r#   rO   Ú
startswithr8   ÚNOTSETr3   )rQ   s    r   Ú__loggerz*create_logger.<locals>.LazyLogger.__loggerŸ   s„   € àÔ!Ð)Ý!ð `Ý#Ð$^Ñ_Ô_Ð_Ý%,Ô%6°t´{Ñ%CÔ%C�Ô"Ø”;×)Ò)¨-Ñ8Ô8ð ;¸TÔ=OÔ=UÕY`ÔYgÒ=gÐ=gØÔ&×/Ò/°	Ñ:Ô:Ð:ØÔ%Ð%r   c                 ó0   •—  ‰| j         dz   |z   ¦  «        S )Nú.)rO   )rQ   ÚsuffixÚ
LazyLoggers     €r   ÚgetChildz*create_logger.<locals>.LazyLogger.getChild©   s   ø€ Ø�:˜dœk¨CÑ/°&Ñ8Ñ9Ô9Ð9r   c                 ó&   —  | j         j        |i |¤ŽS rN   )Ú_LazyLogger__loggerr3   ©rQ   ÚargsÚkws      r   r3   z*create_logger.<locals>.LazyLogger.setLevel¬   s   € Ø)�4”=Ô)¨4Ð6°2Ð6Ð6Ð6r   c                 ó†   — d|v r,|                      d¦  «        |                     di ¦  «        d<    | j        j        |i |¤ŽS ©NÚmsgidÚextra)ÚpopÚ
setdefaultr_   Úlogr`   s      r   ri   z%create_logger.<locals>.LazyLogger.log¯   sG   € Ø˜"ˆ}ˆ}Ø68·f²f¸W±o´o�—’˜g rÑ*Ô*¨7Ñ3Ø$�4”=Ô$ dÐ1¨bÐ1Ð1Ð1r   c                 ó†   — d|v r,|                      d¦  «        |                     di ¦  «        d<    | j        j        |i |¤ŽS rd   )rg   rh   r_   Ú	exceptionr`   s      r   rk   z+create_logger.<locals>.LazyLogger.exception´   sG   € Ø˜"ˆ}ˆ}Ø68·f²f¸W±o´o�—’˜g rÑ*Ô*¨7Ñ3Ø*�4”=Ô*¨DÐ7°BÐ7Ð7Ð7r   c                 ó†   — d|v r,|                      d¦  «        |                     di ¦  «        d<    | j        j        |i |¤ŽS rd   )rg   rh   r_   r%   r`   s      r   r%   z'create_logger.<locals>.LazyLogger.debug¹   óG   € Ø˜"ˆ}ˆ}Ø68·f²f¸W±o´o�—’˜g rÑ*Ô*¨7Ñ3Ø&�4”=Ô&¨Ð3°Ð3Ð3Ð3r   c                 ó†   — d|v r,|                      d¦  «        |                     di ¦  «        d<    | j        j        |i |¤ŽS rd   )rg   rh   r_   r   r`   s      r   r   z&create_logger.<locals>.LazyLogger.info¾   sG   € Ø˜"ˆ}ˆ}Ø68·f²f¸W±o´o�—’˜g rÑ*Ô*¨7Ñ3Ø%�4”=Ô% tÐ2¨rÐ2Ð2Ð2r   c                 ó†   — d|v r,|                      d¦  «        |                     di ¦  «        d<    | j        j        |i |¤ŽS rd   )rg   rh   r_   r   r`   s      r   r   z)create_logger.<locals>.LazyLogger.warningÃ   sG   € Ø˜"ˆ}ˆ}Ø68·f²f¸W±o´o�—’˜g rÑ*Ô*¨7Ñ3Ø(�4”=Ô(¨$Ð5°"Ð5Ð5Ð5r   c                 ó†   — d|v r,|                      d¦  «        |                     di ¦  «        d<    | j        j        |i |¤ŽS rd   )rg   rh   r_   Úerrorr`   s      r   rq   z'create_logger.<locals>.LazyLogger.errorÈ   rm   r   c                 ó†   — d|v r,|                      d¦  «        |                     di ¦  «        d<    | j        j        |i |¤ŽS rd   )rg   rh   r_   Úcriticalr`   s      r   rs   z*create_logger.<locals>.LazyLogger.criticalÍ   sG   € Ø˜"ˆ}ˆ}Ø68·f²f¸W±o´o�—’˜g rÑ*Ô*¨7Ñ3Ø)�4”=Ô)¨4Ð6°2Ð6Ð6Ð6r   rN   )r   Ú
__module__Ú__qualname__rS   Úpropertyr_   r]   r3   ri   rk   r%   r   r   rq   rs   )r\   s   €r   r\   rL   š   sÕ   ø€ € € € € ð	&ð 	&ð 	&ð 	&ð 
ð	&ð 	&ñ 
Œð	&ð	:ð 	:ð 	:ð 	:ð 	:ð	7ð 	7ð 	7ð	2ð 	2ð 	2ð
	8ð 	8ð 	8ð
	4ð 	4ð 	4ð
	3ð 	3ð 	3ð
	6ð 	6ð 	6ð
	4ð 	4ð 	4ð
	7ð 	7ð 	7ð 	7ð 	7r   r\   © )rR   r\   s    @r   r   r   Š   sH   ø€ ð 67ð 67ð 67ð 67ð 67ð 67ð 67ñ 67ô 67ð 67ðp ˆ:�dÑÔÐr   c                   ó"   ‡ — e Zd ZdZˆ fd„Zˆ xZS )r+   )Ú	levelnamerR   r   re   c                 óÊ   •— t          ¦   «                              |¦  «         d|j        dddœ}| j        D ]}t	          ||d ¦  «        }|r|||<   Œt          j        |¦  «        S )NÚlog_messager   ÚCRITICAL)ÚtypeÚtimer   ry   )ÚsuperÚformatÚcreatedÚRECORD_ATTRIBUTESÚgetattrr$   Údumps)rQ   ÚrecordÚdataÚattrÚvalueÚ	__class__s        €r   r€   zJsonFormatter.formatæ   sz   ø€ Ý‰Œ�Š�vÑÔÐà!Ø”NØØ#ð	
ð 
ˆð Ô*ð 	#ð 	#ˆDÝ˜F D¨$Ñ/Ô/ˆEØð #Ø"��T‘
øÝŒz˜$ÑÔÐr   )r   rt   ru   r‚   r€   Ú__classcell__)r‰   s   @r   r+   r+   Õ   s@   ø€ € € € € ðÐð  ð  ð  ð  ð  ð  ð  ð  ð  r   r+   )NN)NNr   r   FFrN   )Ú__doc__rB   r$   r   Úlogging.configÚlogging.handlersr   r&   r"   r   r@   rI   r   r,   r+   rw   r   r   ú<module>rŽ      sä   ððð ð@ €€€Ø €€€Ø €€€Ø Ð Ð Ð Ø Ð Ð Ð Ø 	€	€	€	Ø €€€à€
ðð ð ð ð<ð <ð <ð <ð~ð ð ð&Hð Hð Hð HðV ð  ð  ð  ð  �GÔ%ñ  ô  ð  ð  ð  r   