Current File : //usr/lib64/python3.6/site-packages/borg/__pycache__/logger.cpython-36.pyc
3

y��b�#�@s|dZddlZddlZddlZddlZddlZddlZddlZdaddd�Z	ddd	�Z
d
d�Zddd
�ZGdd�dej
�ZdS)alogging 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
�NFcCs(dj|||j|�}tt�}|j|�dS)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/sr�BORG_LOGGING_CONF�infocCs�d}|rtjj||�}|r�ydtjj|�}t|��}tjj|�WdQRXda	tj
t�}tj
d�}	||	_|j
dj|��tt_dStk
r�}
zt|
�}WYdd}
~
XnXtj
d�}tj|�}|r�|r�d}nd}|r�t|�ntj|�}
|j|
�tj
d�}	|
|	_||	_t	�r.|j�r.|jdj�|jj�|j|�|j|j��da	tj
t�}|�rl|jd	j||��|j
d
�tt_|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.
    NTZborgz+using logging configuration read from "{0}"�z/$LOG %(levelname)s %(name)s Remote: %(message)sz%(message)srz*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�debugrr�warnings�showwarning�	Exception�strZ
StreamHandler�
JsonFormatter�	FormatterZsetFormatter�	formatterZhandlers�close�clearZ
addHandler�setLevel�upperr)�streamZ
conf_fnameZenv_var�levelZis_serverZerr_msg�fr
Zborg_logger�errZhandlerZfmtr&rrr�
setup_logging8sN












r/cCs\yBtj�j}tj|�}x&|dks*|jtkr<|j}tj|�}qW|jStk
rVtSXdS)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�modulerrr�find_parent_modulews

r5csG�fdd�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.
    csneZdZddd�Zedd��Z�fdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�ZdS)z!create_logger.<locals>.LazyLoggerNcSs|pt�|_d|_dS)N)r5�_LazyLogger__name�_LazyLogger__real_logger)�self�namerrr�__init__�sz*create_logger.<locals>.LazyLogger.__init__cSsP|jdkrJtstd��tj|j�|_|jjd�rJ|jjtjkrJ|jj	d�|jS)Nz8tried to call a logger before setup_logging() was calledzborg.debug.ZWARNING)
r7rr"rrr6�
startswithr,ZNOTSETr))r8rrrZ__logger�s
z*create_logger.<locals>.LazyLogger.__loggercs�|jd|�S)N�.)r6)r8�suffix)�
LazyLoggerrr�getChild�sz*create_logger.<locals>.LazyLogger.getChildc_s|jj||�S)N)�_LazyLogger__loggerr))r8�args�kwrrrr)�sz*create_logger.<locals>.LazyLogger.setLevelc_s,d|kr|jd�|jdi�d<|jj||�S)N�msgid�extra)�pop�
setdefaultr@�log)r8rArBrrrrG�sz%create_logger.<locals>.LazyLogger.logc_s,d|kr|jd�|jdi�d<|jj||�S)NrCrD)rErFr@�	exception)r8rArBrrrrH�sz+create_logger.<locals>.LazyLogger.exceptionc_s,d|kr|jd�|jdi�d<|jj||�S)NrCrD)rErFr@r)r8rArBrrrr�sz'create_logger.<locals>.LazyLogger.debugc_s,d|kr|jd�|jdi�d<|jj||�S)NrCrD)rErFr@r)r8rArBrrrr�sz&create_logger.<locals>.LazyLogger.infoc_s,d|kr|jd�|jdi�d<|jj||�S)NrCrD)rErFr@r)r8rArBrrrr�sz)create_logger.<locals>.LazyLogger.warningc_s,d|kr|jd�|jdi�d<|jj||�S)NrCrD)rErFr@�error)r8rArBrrrrI�sz'create_logger.<locals>.LazyLogger.errorc_s,d|kr|jd�|jdi�d<|jj||�S)NrCrD)rErFr@�critical)r8rArBrrrrJ�sz*create_logger.<locals>.LazyLogger.critical)N)r�
__module__�__qualname__r:�propertyr@r?r)rGrHrrrrIrJr)r>rrr>�s

r>r)r9r)r>rr�s8rcs eZdZdZ�fdd�Z�ZS)r$�	levelnamer9rrCcsNt�j|�d|jddd�}x&|jD]}t||d�}|r$|||<q$Wtj|�S)NZlog_messagerZCRITICAL)�typeZtimerrN)�superrZcreated�RECORD_ATTRIBUTES�getattrr�dumps)r8�record�data�attr�value)�	__class__rrr�szJsonFormatter.format)rNr9rrC)rrKrLrQr�
__classcell__rr)rXrr$�s
r$)NN)NNrrFF)N)�__doc__r0rrZlogging.configZlogging.handlersrr rrr/r5rr%r$rrrr�<module>s
	
?
K