509318396
Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­
<!DOCTYPE html>
<html>
3
y¾œbË#  ã               @   s|   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d„Z	ddd	„Z
d
d„ Zddd„ZG d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             C   s(   dj |||j| ƒ}ttƒ}|j|ƒ d S )Nz{0}:{1}: {2}: {3})ÚformatÚ__name__Úcreate_loggerÚwarning)ÚmessageÚcategoryÚfilenameÚlinenoÚfileÚlineÚmsgÚlogger© r   ú/usr/lib64/python3.6/logger.pyÚ_log_warning/   s    r   ÚBORG_LOGGING_CONFÚinfoc             C   s€  d}|rt jj||ƒ}|rªydt jj|ƒ}t|ƒ�}tjj|ƒ W dQ R X da	tj
tƒ}tj
dƒ}	||	_|jdj|ƒƒ tt_dS  tk
r¨ }
 zt|
ƒ}W Y dd}
~
X nX tj
dƒ}tj| ƒ}|rÎ| rÎd}nd}|rÞt|ƒntj|ƒ}|j|ƒ tj
dƒ}	||	_||	_t	�r.|j�r.|jd jƒ  |jjƒ  |j|ƒ |j|jƒ ƒ da	tj
tƒ}|�rl|jd	j||ƒƒ |j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.
    NTZborgz+using logging configuration read from "{0}"Ú z/$LOG %(levelname)s %(name)s Remote: %(message)sz%(message)sr   z*setup_logging for "{0}" failed with "{1}".z,using builtin fallback logging configuration) ÚosÚenvironÚgetÚpathÚabspathÚopenÚloggingÚconfigZ
fileConfigÚ
configuredÚ	getLoggerr   ÚjsonÚdebugr   r   ÚwarningsÚshowwarningÚ	ExceptionÚstrZStreamHandlerÚJsonFormatterÚ	FormatterZsetFormatterÚ	formatterZhandlersÚcloseÚclearZ
addHandlerÚsetLevelÚupperr   )ÚstreamZ
conf_fnameZenv_varÚlevelZis_server   Zerr_msgÚfr   Zborg_loggerÚerrZhandlerZfmtr&   r   r   r   Úsetup_logging8   sN    











r/   c              C   s\   yBt jƒ j} t j| ƒ}x&|dks*|jtkr<| j} t j| ƒ}qW |jS  tk
rV   tS X dS )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.
    N)ÚinspectZcurrentframeÚf_backZ	getmoduler   ÚAttributeError)ÚframeÚmoduler   r   r   Úfind_parent_modulew   s    

r5   c                s   G ‡ fd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                   sn   e Zd Zddd„Zedd„ ƒZ‡ fdd„Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ ZdS )z!create_logger.<locals>.LazyLoggerNc             S   s   |pt ƒ | _d | _d S )N)r5   Ú_LazyLogger__nameÚ_LazyLogger__real_logger)ÚselfÚnamer   r   r   Ú__init__›   s    z*create_logger.<locals>.LazyLogger.__init__c             S   sP   | j d krJtstdƒ‚tj| jƒ| _ | jjdƒrJ| j jtjkrJ| j j	dƒ | j S )Nz8tried to call a logger before setup_logging() was calledzborg.debug.ZWARNING)
r7   r   r"   r   r   r6   Ú
startswithr,   ZNOTSETr)   )r8   r   r   r   Z__loggerŸ   s    
z*create_logger.<locals>.LazyLogger.__loggerc                s   ˆ | j d | ƒS )NÚ.)r6   )r8   Úsuffix)Ú
LazyLoggerr   r   ÚgetChild©   s    z*create_logger.<locals>.LazyLogger.getChildc             _   s   | j j||ŽS )N)Ú_LazyLogger__loggerr)   )r8   ÚargsÚkwr   r   r   r)   ¬   s    z*create_logger.<locals>.LazyLogger.setLevelc             _   s,   d|kr|j dƒ|jdi ƒd< | jj||ŽS )NÚmsgidÚextra)ÚpopÚ
setdefaultr@   Úlog)r8   rA   rB   r   r   r   rG   ¯   s    z%create_logger.<locals>.LazyLogger.logc             _   s,   d|kr|j dƒ|jdi ƒd< | jj||ŽS )NrC   rD   )rE   rF   r@   Ú	exception)r8   rA   rB   r   r   r   rH   ´   s    z+create_logger.<locals>.LazyLogger.exceptionc             _   s,   d|kr|j dƒ|jdi ƒd< | jj||ŽS )NrC   rD   )rE   rF   r@   r   )r8   rA   rB   r   r   r   r   ¹   s    z'create_logger.<locals>.LazyLogger.debugc             _   s,   d|kr|j dƒ|jdi ƒd< | jj||ŽS )NrC   rD   )rE   rF   r@   r   )r8   rA   rB   r   r   r   r   ¾   s    z&create_logger.<locals>.LazyLogger.infoc             _   s,   d|kr|j dƒ|jdi ƒd< | jj||ŽS )NrC   rD   )rE   rF   r@   r   )r8   rA   rB   r   r   r   r   Ã   s    z)create_logger.<locals>.LazyLogger.warningc             _   s,   d|kr|j dƒ|jdi ƒd< | jj||ŽS )NrC   rD   )rE   rF   r@   Úerror)r8   rA   rB   r   r   r   rI   È   s    z'create_logger.<locals>.LazyLogger.errorc             _   s,   d|kr|j dƒ|jdi ƒd< | jj||ŽS )NrC   rD   )rE   rF   r@   Úcritical)r8   rA   rB   r   r   r   rJ   Í   s    z*create_logger.<locals>.LazyLogger.critical)N)r   Ú
__module__Ú__qualname__r:   Úpropertyr@   r?   r)   rG   rH   r   r   r   rI   rJ   r   )r>   r   r   r>   š   s   

r>   r   )r9   r   )r>   r   r   Š   s    8r   c                   s    e Zd ZdZ‡ fdd„Z‡  ZS )r$   Ú	levelnamer9   r   rC   c                sN   t ƒ j|ƒ d|jdddœ}x&| jD ]}t||d ƒ}|r$|||< q$W tj|ƒS )NZlog_messager   ZCRITICAL)ÚtypeZtimer   rN   )Úsuperr   ZcreatedÚRECORD_ATTRIBUTESÚgetattrr   Údumps)r8   ÚrecordÚdataÚattrÚvalue)Ú	__class__r   r   r   æ   s    zJsonFormatter.format)rN   r9   r   rC   )r   rK   rL   rQ   r   Ú__classcell__r   r   )rX   r   r$   Õ   s
      r$   )NN)NNr   r   FF)N)Ú__doc__r0   r   r   Zlogging.configZlogging.handlersr   r    r   r   r/   r5   r   r%   r$   r   r   r   r   Ú<module>   s   
	
?
K