/usr/lib/python3.10/logging/__pycache__
Edit: /usr/lib/python3.10/logging/__pycache__/handlers.cpython-310.pyc (44684B)
o
9j @ s d Z ddlZddlZddlZddlZddlZddlZddlZddlZddl m
Z
mZmZ ddl
Z
ddlZddlZdZdZdZdZdZdZd ZG d
d dejZG dd
d
eZG dd deZG dd dejZG dd dejZG dd deZG dd dejZG dd dejZ G dd dejZ!G dd dejZ"G dd dejZ#G d d! d!e#Z$G d"d# d#ejZ%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-2021 Vinay Sajip. All Rights Reserved.
To use, simply 'import logging.handlers' and log away!
N)ST_DEVST_INOST_MTIMEi<# i=# i># i?# i Q c @ s: e Zd ZdZdZdZdddZdd Zdd Zd
d Z dS )
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 s. t jj| |||||d || _|| _|| _dS )zA
Use the specified filename for streamed logging
modeencodingdelayerrorsN)loggingFileHandler__init__r r r selffilenamer r r
r r '/usr/lib/python3.10/logging/handlers.pyr 6 s
zBaseRotatingHandler.__init__c C sF z| |r
| tj| | W dS ty" | | Y dS w )z
Emit a record.
Output the record to the file, catering for rollover as described
in doRollover().
N)shouldRollover
doRolloverr r
emit ExceptionhandleErrorr recordr r r r A s
zBaseRotatingHandler.emitc C s t | js |}|S | |}|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.
)callablenamer)r default_nameresultr r r rotation_filenameO s
z%BaseRotatingHandler.rotation_filenamec C s: t | jstj|rt|| dS dS | || 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 rotatorospathexistsrename)r sourcedestr r r rotateb s
zBaseRotatingHandler.rotate)NFN)
__name__
__module____qualname____doc__r r r r r r' r r r r r - s
r c @ s. e Zd ZdZ dddZdd 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 sD |dkrd}d|vrt |}tj| |||||d || _|| _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- br r
r N)io
text_encodingr r maxBytesbackupCount)r r r r2 r3 r r
r r r r r | s
zRotatingFileHandler.__init__c C s | j r| j d| _ | jdkrct| jd ddD ]/}| d| j|f }| d| j|d f }tj|rHtj|rBt | t
|| q| | jd }tj|r\t | | | j| | jsm|
| _ dS dS )z<
Do a rollover, as described in __init__().
Nr z%s.%dz.1)streamcloser3 ranger baseFilenamer! r" r# remover$ r' r
_open)r isfndfnr r r r s*
zRotatingFileHandler.doRolloverc C sz t j| jrt j| jsdS | jdu r| | _| jdkr;d| | }| j dd | j
t| | jkr;dS dS )z
Determine if rollover should occur.
Basically, see if the supplied record would cause the file to exceed
the size limit we have.
FNr z%s
T)r! r" r# r9 isfiler6 r; r2 formatseektelllenr r msgr r r r s
z"RotatingFileHandler.shouldRollover)r- r r NFN)r( r) r* r+ r r r r r r r r, w s
$r, c @ s@ e Zd ZdZ dddZd d
Zdd Zd
d Zdd ZdS )TimedRotatingFileHandlerz
Handler for logging to a file, rotating the log file at certain timed
intervals.
If backupCount is > 0, when rollover is done, no more than backupCount
files are kept - the oldest ones are deleted.
hr4 r NFc
C s t |}tj| |d||| d | | _|| _|| _|| _| jdkr-d| _ d| _
d| _nt| jdkr