%PDF- %PDF-
Direktori : /snap/core20/2318/lib/python3.8/logging/__pycache__/ |
Current File : //snap/core20/2318/lib/python3.8/logging/__pycache__/handlers.cpython-38.pyc |
U k�]eq� � @ sz d Z ddlZddlZddlZddlZddlZddlZddlZddlm Z m Z mZ ddlZddl Z ddlZdZdZdZdZdZdZd ZG d d� dej�ZG dd � d e�ZG dd� de�ZG dd� dej�ZG dd� dej�ZG dd� de�ZG dd� dej�ZG dd� dej�ZG dd� dej�Z G dd� dej�Z!G dd� dej�Z"G d d!� d!e"�Z#G d"d#� d#ej�Z$G d$d%� d%e%�Z&dS )&z� Additional handlers for the logging package for Python. The core package is based on PEP 282 and comments thereto in comp.lang.python. Copyright (C) 2001-2016 Vinay Sajip. All Rights Reserved. To use, simply 'import logging.handlers' and log away! � N)�ST_DEV�ST_INO�ST_MTIMEi<# i=# i># i?# i �Q c @ s2 e Zd ZdZddd�Zdd� Zdd � Zd d� ZdS ) �BaseRotatingHandlerz� Base class for handlers that rotate log files at a certain point. Not meant to be instantiated directly. Instead, use RotatingFileHandler or TimedRotatingFileHandler. NFc C s0 t j�| ||||� || _|| _d| _d| _dS )zA Use the specified filename for streamed logging N)�logging�FileHandler�__init__�mode�encoding�namer�rotator��self�filenamer r �delay� r �&/usr/lib/python3.8/logging/handlers.pyr 3 s zBaseRotatingHandler.__init__c C sH z$| � |�r| �� tj�| |� W n tk rB | �|� Y nX dS )z� Emit a record. Output the record to the file, catering for rollover as described in doRollover(). N)�shouldRollover� doRolloverr r �emit� Exception�handleError�r �recordr r r r = s zBaseRotatingHandler.emitc C s t | j�s|}n | �|�}|S )a� Modify the filename of a log file when rotating. This is provided so that a custom filename can be provided. The default implementation calls the 'namer' attribute of the handler, if it's callable, passing the default name to it. If the attribute isn't callable (the default is None), the name is returned unchanged. :param default_name: The default name for the log file. )�callabler )r Zdefault_name�resultr r r �rotation_filenameK s z%BaseRotatingHandler.rotation_filenamec C s4 t | j�s$tj�|�r0t�||� n| �||� dS )aL When rotating, rotate the current log. The default implementation calls the 'rotator' attribute of the handler, if it's callable, passing the source and dest arguments to it. If the attribute isn't callable (the default is None), the source is simply renamed to the destination. :param source: The source filename. This is normally the base filename, e.g. 'test.log' :param dest: The destination filename. This is normally what the source is rotated to, e.g. 'test.log.1'. N)r r �os�path�exists�rename)r �source�destr r r �rotate^ s zBaseRotatingHandler.rotate)NF)�__name__� __module__�__qualname__�__doc__r r r r$ r r r r r - s r c @ s* e Zd ZdZddd�Zdd � Zd d� ZdS ) �RotatingFileHandlerz� Handler for logging to a set of files, which switches from one file to the next when the current file reaches a certain size. �ar NFc C s. |dkrd}t �| ||||� || _|| _dS )a� Open the specified file and use it as the stream for logging. By default, the file grows indefinitely. You can specify particular values of maxBytes and backupCount to allow the file to rollover at a predetermined size. Rollover occurs whenever the current log file is nearly maxBytes in length. If backupCount is >= 1, the system will successively create new files with the same pathname as the base file, but with extensions ".1", ".2" etc. appended to it. For example, with a backupCount of 5 and a base file name of "app.log", you would get "app.log", "app.log.1", "app.log.2", ... through to "app.log.5". The file being written to is always "app.log" - when it gets filled up, it is closed and renamed to "app.log.1", and if files "app.log.1", "app.log.2" etc. exist, then they are renamed to "app.log.2", "app.log.3" etc. respectively. If maxBytes is zero, rollover never occurs. r r* N)r r �maxBytes�backupCount)r r r r+ r, r r r r r r x s zRotatingFileHandler.__init__c C s� | j r| j �� d| _ | jdkr�t| jd dd�D ]^}| �d| j|f �}| �d| j|d f �}tj�|�r2tj�|�r�t� |� t� ||� q2| �| jd �}tj�|�r�t� |� | �| j|� | js�| � � | _ dS )z< Do a rollover, as described in __init__(). Nr � ���z%s.%dz.1)�stream�closer, �ranger �baseFilenamer r r �remover! r$ r �_open)r �iZsfn�dfnr r r r � s&