HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.109.1.lve.el8.x86_64 #1 SMP Thu Mar 5 20:23:46 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.30
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/_logging/__pycache__/impl.cpython-310.pyc
o

�N�g���@sndZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZdZ
e_
dZe_dZe_dZe_ddlZddlmZddlmZdd	lmZdd
lmZddlmZddlmZdd
lmZddlmZddlm Z m!Z!ddl"m#Z#ej$ej%ej&ej'eej(e
eeej)d�
Z*dd�e*�+�D�Z,e#d�e#dd�e#dd�e#dd�e#dd�e#dd�e#dd�e#dd�e#dd�e#d�e#dd�e#dd�d�e#d�e#dd�e#d�e#d�e#d�e#dd�e#d�e#d�e#d�e#d�e#dd�e#dd�d�e#dd�e#dd�d�Z-dd�e.e*�+�d d!�d"�D�Z/e�0d#�Z1d$Z2d%Z3d&Z4d'Z5d(Z6Gd)d*�d*ej7�Z8Gd+d,�d,e8�Z9d-d.�Z:d/d0�Z;e;e8�e�<�Z=Gd1d2�d2e=ed3�Z>d4d5�Z?d6d7�Z@d8d9�ZAd:d;�ZBd<d=�ZCd>d?�ZDdpd@dA�ZEdBdC�ZFe�<�e>u�r�zddlGmHmImJZKWneL�y�dZKYnwe�Me>�e�NedD�e�Ne
dE�e�NedF�e�NedG�eKdu�r�e>jOe>_PejQjR�s�ejQ�Se�eE�ejQ�TeD��e�UeV�ZWdHdI�ZXdJdK�ZYdLdM�ZZdqdNdO�Z[dPdQ�Z\dRdS�Z]dTdU�Z^						drdVdW�Z_dXdY�Z`dZd[�Zad\d]�Zbd^d_�Zcd`da�Zddbdc�Zeddde�Zfdfdg�Zgdhdi�Zhdjdk�Zidldm�Zje�UeV�ejke	jlfdndo�Zmeme_ndS)szh
    salt._logging.impl
    ~~~~~~~~~~~~~~~~~~

    Salt's logging implementation classes/functionality
�N���i�)�DeferredStreamHandler)�RotatingFileHandler)�
StreamHandler)�
SysLogHandler)�WatchedFileHandler)�LoggingMixinMeta)�LoggingRuntimeError)�RequestContext)�freeze�
ImmutableDict)�
TextFormat)
�all�debug�error�criticalZgarbage�infoZprofile�quiet�trace�warningcCsi|]\}}||�qS�r)�.0�k�vrr�F/opt/saltstack/salt/lib/python3.10/site-packages/salt/_logging/impl.py�
<dictcomp>4sr�resetZboldZredZyellowZgreenZcyanZmagentaZblue)�QUIET�CRITICAL�ERROR�WARNING�INFO�PROFILE�DEBUG�TRACE�GARBAGE�NOTSETZSUBDEBUGZ
SUBWARNING)�levels�msgs�name�processcCsg|]}|d�qS)rr)r�lrrr�
<listcomp>`sr.cCs|dS)Nrr)�xrrr�<lambda>`sr0��keyz-(?P<name>%%\(name\)(?:\-(?P<digits>[\d]+))?s)z[JID: %(jid)s]z%H:%M:%Sz%Y-%m-%d %H:%M:%Sz[%(levelname)-8s] %(message)sz\%(asctime)s,%(msecs)03d [%(name)-17s:%(lineno)-4d][%(levelname)-8s][%(process)d] %(message)sc@�eZdZdd�ZdS)�
SaltLogRecordcOs`tjj|g|�Ri|��dt|j�d�d�|_dt|j�d�d�|_dt|j�d�d�|_	dS)N�[z<17�]�<8z>5)
�logging�	LogRecord�__init__�strr+Zbracketname�	levelnameZbracketlevelr,Zbracketprocess)�self�args�kwargsrrrr:mszSaltLogRecord.__init__N��__name__�
__module__�__qualname__r:rrrrr4l�r4c@r3)�SaltColorLogRecordcOs�tj|g|�Ri|��td�}td�|j|�}td�|j|�}d�tdt|j�|�|_	|�dt|j�d�d|��|_
d	�td
t|j�|�|_|�|�
��|��|_dS)Nrr)r*z{}[{:<17}]{}r+r5r7r6z{}[{:>5}]{}r,)r4r:r�
LOG_COLORS�getr<�formatr;r+Z	colornameZ
colorlevelr,Zcolorprocess�
getMessageZcolormsg)r=r>r?rZclevelZcmsgrrrr:us��zSaltColorLogRecord.__init__Nr@rrrrrEtrDrEcC�ztjWStyYdSw)z-
    Get the logging  log record factory
    N)�get_log_record_factory�__factory__�AttributeErrorrrrrrK��
�rKcCs|t_t�|�dS)z-
    Set the logging  log record factory
    N)rKrLr8�setLogRecordFactory)�factoryrrr�set_log_record_factory�srQcsHeZdZe�Z�fdd�Z						d
dd�Z			ddd	�Z�ZS)�SaltLoggingClassc	sFt��|�}z�ttttjjj�td��}|dkrd}tj	j
D]w}|t�ur&q|j}|s,q|j
s3|��|��|j�dd�}t�|�}|sN|��|WSd|��vr]|��|WS|�d�}|rj|rj|��ss|��|WSt|�|kr�|�|�d�d�}tj|||jd�}|�|�|��qW|Sty�Y|Sw)	ad
        We override `__new__` in our logging logger class in order to provide
        some additional features like expand the module name padding if length
        is being used, and also some Unicode fixes.

        This code overhead will only be executed when the class is
        instantiated, i.e.:

            logging.getLogger(__name__)

        r1�P�%z%%�digitsr+z%%(name)-%ds��datefmt)�super�__new__�len�max�listr8�Logger�manager�
loggerDict�root�handlers�get_temp_handler�	formatter�lock�
createLock�acquire�_fmt�replace�MODNAME_PATTERN�search�release�	groupdict�group�isdigit�int�	FormatterrW�setFormatter�
ValueError)	�clsr>�instanceZmax_logger_length�handlerrc�fmt�matchrU��	__class__rrrY�sR�






�

�*��zSaltLoggingClass.__new__NFrc
Cs0|duri}|	rt|�|jvrdS|j�t|��tj�di��dd�}
tj�di��dd�}|
dur7|
|d<|dur?||d<|rG|rGtd��|durdt|t�rXt�|t	j
�}nt|t�sdtd�
|���|durmd|i}n||d<ztj||||||||d�WdSty�tj|||||||d	�YdSw)
N�data�jid�opts�log_fmt_jidz>Only one of 'exc_info' and 'exc_info_on_loglevel' is permittedzaThe value of 'exc_info_on_loglevel' needs to be a logging level or a logging level name, not '{}'�exc_info_on_loglevel)�exc_info�extra�
stack_info�
stacklevel)rr�r�)r;�	ONCECACHE�addr�currentrGr�
isinstance�
LOG_LEVELSr8r!ro�RuntimeErrorrH�LOGGING_LOGGER_CLASS�_log�	TypeError)r=�level�msgr>rr�r�r�r~�onceZcurrent_jidr}rrrr��sj�
�
��
�
��zSaltLoggingClass._logcCsL|	�d�}|	�dd�}|r|	�d�}
|
d|i}|	sd}	z
t}|dkr%d}Wnty1d}Ynwt|t�rOz|�|d�}WntyN|�|d�}Ynw|}g}|D]*}t|t�rzz|�|�|d��WqUtyy|�|�|d��YqUw|�|�qUt|�}t	�
||||||||||
�
}|dur�t��|_
d|_||_||_|S)	Nr~r{�r}�ascii�utf-8rh�ignore)�popZ__salt_system_encoding__�	NameErrorr��bytes�decode�UnicodeDecodeError�append�tupler��
makeRecord�sysrZexc_info_on_loglevel_instanceZexc_info_on_loglevel_formattedr~r{)r=r+r��fn�lnor�r>r�funcr��sinfor~r{r}Zsalt_system_encodingZ_msg�_args�itemZ	logrecordrrrr�3sR

��
�
��
zSaltLoggingClass.makeRecord)NNFrNF�NNN)	rArBrC�setr�rYr�r��
__classcell__rrrxrrR�sG
�W�rR)�	metaclasscCsT|durtjSt|t�r|Szt|��WSty)|r$t�d|�tj	YSw)z�
    Return an integer matching a logging level.
    Return logging.ERROR when not matching.
    Return logging.WARNING when the passed level is None
    NzrCould not translate the logging level string '%s' into an actual logging level integer. Returning 'logging.ERROR'.)
r8r"r�ror��lower�KeyError�logrr!)r�rrr�get_logging_level_from_string|s
�
�r�cCrJ)z/
    Return the logging options dictionary
    N)�set_logging_options_dict�__options_dict__rMrrrr�get_logging_options_dict�rNr�cCs>zttjt�rtd��Wn	tyYnw|t_t|�dS)zY
    Create a logging related options dictionary based off of the loaded salt config
    zDThe logging options have been frozen. They can no longer be changed.N)r�r�r�rr�rM�set_lowest_log_level_by_opts)r|rrrr��s���r�cCsttj�t_dS)zJ
    Turn the logging options dictionary into an immutable dictionary
    N)r
r�r�rrrr�freeze_logging_options_dict�s
�r�cC�
t�duS)z=
    Is the temporary deferred stream handler configured
    N)rbrrrr�is_temp_handler_configured��
r�cCrJ)z3
    Get the temporary deferred stream handler
    N)�setup_temp_handler�__handler__rMrrrrrb�rNrbcCs�t�}|durt|�}|j|kr|�|�dS|durtj}t|�}d}tjjD]}t|d�s0q(|j	t
jur8nq(tt
j�}t
�|j�|�|�tjttd�}|�|�tj�|�|t_dS)z5
    Setup the temporary deferred stream handler
    N�streamrV)rbr�r��setLevelr8r"r`ra�hasattrr�r��stderrr�atexit�register�flushrp�DFLT_LOG_FMT_CONSOLE�DFLT_LOG_DATEFMTrq�
addHandlerr�r�)�	log_levelrurcrrrr��s.


�



r�cCsbt�}|dur/tjjdd�D]}||ur)tjj�|�|�tjj�|��nqdt_dSdS)z8
    Shutdown the temporary deferred stream handler
    N)	rbr8r`ra�removeZsync_with_handlers�closer�r�)Ztemp_handlerrurrr�shutdown_temp_handler�s�
�r�rr$r&r'cCrJ)z(
    Get the console stream handler
    N)�setup_console_handlerr�rMrrrr�get_console_handler$rNr�cCr�)z2
    Is the console stream handler configured
    N)r�rrrr�is_console_handler_configured.r�r�cC�:t�}|durtj�|�|��dt_t�t	�dSdS)z-
    Shutdown the console stream handler
    N)
r�r8r`�
removeHandlerr�r�r�r��
unregister�shutdown_console_handler)Zconsole_handlerrrrr�5��r�cCs�t�r
t�d�dSt�t�t�dt|||d��|dur!tj	}t
|�}tt�d}tj
jD]}|t�ur7q/t|d�s=q/|jtjurEnq/ttj�}|�|�|sTt}|sXt}tj||d�}|�|�tj
�|�|t_dS)z*
    Setup the console stream handler
    z"Console logging already configuredNzSetting up console logging: %s�r��
log_format�date_formatr�rV)r�r�rr�r�r�r�dictr8r"r�rQrEr`rarbr�r�r�r�rr�r�r�rprqr�r�r�)r�r�r�rurcrrrr�As>

�

�



r�cCrJ)z"
    Get the log file handler
    N)�setup_logfile_handlerr�rMrrrr�get_logfile_handlerurNr�cCr�)z,
    Is the log file handler configured
    N)r�rrrr�is_logfile_handler_configuredr�r�cCr�)z'
    Shutdown the log file handler
    N)
r�r8r`r�r�r�r�r�r��shutdown_logfile_handler)Zlogfile_handlerrrrr��r�r�cCst�r
t�d�dSt�t�t�dt|||||||d��|dur)t�d�dS|dur0tj	}t
|�}tj�
|�}|jdv�rtjtjd�}|jdkr�|jr�t�|j�}	|	j��}
z|
�d	�skd
}
t|	���|d<n	t|	��j�|d<Wn2ty�}ztd|���|�d}~ww|jr�t�|j�}	|	j��}
|
�d	�s�td
|
�d���nd
}
tt|
d�}|dur�td
|
�d���||d<|jdvr�|j|j p�tj!j"f|d<|jdkr�tj#|d<n|jdkr�|�$dd�z	tdi|��}
Wnyt�y}ztd|���|�d}~ww|du�rddl%}|j&j'�(�}ddl)}ddl*}|j&j+�,d��|j&j-�.|g|�Wd�n	1�s7wYz|dk�rMt/|d||ddd�}
nt0|dddd�}
Wnt�ygt�d|�YdSw|
�1|�|�srt2}|�swt3}tj4||d�}|
�5|�tj6�7|
�|
t8_9dS)a�
    Setup the log file handler

    Since version 0.10.6 we support logging to syslog, some examples:

        tcp://localhost:514/LOG_USER
        tcp://localhost/LOG_DAEMON
        udp://localhost:5145/LOG_KERN
        udp://localhost
        file:///dev/log
        file:///dev/log/LOG_SYSLOG
        file:///dev/log/LOG_DAEMON

    The above examples are self explanatory, but:
        <file|udp|tcp>://<host|socketpath>:<port-if-required>/<log-facility>

    Thinking on doing remote logging you might also be thinking that
    you could point Salt's logging to the remote syslog. **Please Don't!**
    An issue has been reported when doing this over TCP where the logged lines
    get concatenated. See #3061.

    The preferred way to do remote logging is setup a local syslog, point
    Salt's logging to the local syslog(unix socket is much faster) and then
    have the local syslog forward the log messages to the remote syslog.
    z"Logfile logging already configuredNzSetting up log file logging: %s��log_pathr�r�r��	max_bytes�backup_count�userz5log_path setting is set to `None`. Nothing else to do)�tcp�udp�file)�facility�socktyper�ZLOG_�LOG_USER�addressz,Failed to setup the Syslog logging handler: zThe syslog facility 'z' is not knownr�)r�r�r�r�r��ar�)�modeZmaxBytesZbackupCount�encoding�delay)r�r�r�z?Failed to open log file, do you have permission to write to %s?rVr):r�r�rr�r�r�rr�r8r"r��urllib�parse�urlparse�schemerr��socket�
SOCK_DGRAM�path�pathlib�Path�stem�upper�
startswithr;�resolve�parent�OSErrorr�getattr�hostname�portraZSYSLOG_UDP_PORT�SOCK_STREAMr�Zsalt.utils.user�utilsr�Zget_userZsalt.utils.filesZsalt.utils.verify�filesZ	set_umaskZverifyZverify_log_filesrr	r��DFLT_LOG_FMT_LOGFILE�DFLT_LOG_DATEFMT_LOGFILErprqr`r�r�r�)r�r�r�r�r�r�r�Zparsed_log_pathZsyslog_optsr�Z
facility_name�excr�ru�saltrcrrrr��s�"

��
�

�����


��
�
�

�
����
�
�	����



r�cCrJ�z+
    Get the extended logging handlers
    N)�setup_extended_logging�__handlers__rMrrrr�get_extended_logging_handlersHrNr�cCst�}|dur	dSdS)z6
    Are the extended logging handlers configured
    NFT)r�)�extended_logging_handlersrrr�is_extended_logging_configuredRsrcCs<t�}|r|D]}tj�|�|��qt�t�dt_	dS)z0
    Shutdown the extended logging handlers
    N)
r�r8r`r�r�r�r��shutdown_extended_loggingr�r�)rrurrrr\s


rc
Cs*t�durdSddl}t�t�tjjdd�}|j�	|�}g}|�
�D]Z\}}t�d|�t
tjj�}|�}t|tj�rBt|�}n|dusK|dgkrRt�d|�q$|g}|D]&}	|	skt
tjj�|krkt�d||�qWt�d||	�|�|	�tj�|	�qWq$tjjD]}	|	|vr�q�|�|	�q�|t_dS)	zC
    Setup the extended logging handlers, internal or external
    TNrzProcessing 'log_handlers.%s'Fz�The `log_handlers.%s.setup_handlers()` function returned `False` which means no logging handler was configured on purpose. Continuing...z�The `log_handlers.%s`, did not return any handlers and the global handlers count did not increase. This could be a sign that `log_handlers.%s` is not working as expected.z.Adding the '%s' provided logging handler: '%s')rZsalt.loaderr�r�rr8r`ra�loaderZlog_handlers�itemsr�rrZr��types�
GeneratorTyper\rr�r�r�r�)
r|r�Zinitial_handlersZ	providersZadditional_handlersr+Zget_handlers_funcZinitial_handlers_countrarurrrr�isJ


��
�
r�cCs.|��D]\}}t�|�}|�t|��qdSr�)rr8�	getLoggerr�r�)�log_granular_levelsZhandler_nameZ
handler_level�_loggerrrr�setup_log_granular_levels�s
�r
c	Cs�t�}|s	td��|�dd�rt�st|d|d|dd�|�dd�rXt�sX|d	p/|d}|d
krS|�d�p:d}t||||d
|d|d|d|dd�nt��t_	|�dd�ret
�set|�|�dd�rqt|d�t
�dS)Nz*The logging options have not been set yet.Zconfigure_console_loggerTr�Zlog_fmt_consoleZlog_datefmtr�Zconfigure_file_logger�log_level_logfiler�log_file_keyZlog_fileZlog_fmt_logfileZlog_datefmt_logfileZlog_rotate_max_bytesZlog_rotate_backup_countr�r�Zconfigure_ext_handlersZconfigure_granular_levelsr)r�r�rGr�r�r�r�r8�NullHandlerr�rr�r
r�)r|Zlog_file_levelrrrr�
setup_logging�sD
����


��
rcCs8t�rt�t�rt�t�rt�t�rt�dSdS�N)r�r�rrr�r�r�r�rrrr�shutdown_logging�s
�rcCsDztjt��kWSty!t��jdkrt��t_YdSYdSw)z2
    Check to see if this is the main process
    �MainProcessTF)�in_mainprocessZ__pid__�os�getpidrM�multiprocessing�current_processr+rrrrr�s
�rcCrJ)z"
    Get the lowest log level
    N)�set_lowest_log_level�
__log_level__rMrrrr�get_lowest_log_level�rNrcCs|t_tj�|�dS)z"
    Set the lowest log level
    N)rrr8r`r�)r�rrrrsrcCsTt|�d��t|�d��g}|�di���D]	}|�t|��qt|�}t|�dS)z7
    Set the lowest log level by the passed config
    r�rrN)r�rG�valuesr��minr)r|Z
log_levelsr�rrrr�s�r�cCs�|jdkrdSd}zd�||j|d�||||�����}Wnty.d�||j|�}Ynwz|�|�Wn tyVz	|�|d�Wn
tySt|�YnwYnwz
t�	|||�WdStykYdSw)zB
    This function will log all un-handled python exceptions.
    �KeyboardInterruptNzFAn un-handled exception was caught by Salt's global exception handler:z{}
{}: {}
{}r�z&{}
{}: {}
(UNABLE TO FORMAT TRACEBACK)�
)
rArH�join�strip�	Exceptionr�write�printr��__excepthook__)�exc_type�	exc_value�
exc_tracebackr	�_stderrZ_format_exceptionr�rrr�"__global_logging_exception_handlers@
������	�r(rr�)NNNrrN)o�__doc__r�r8rrr��rer�r��	tracebackr�urllib.parser�r$r&r'rZsalt.defaults.exitcodesr�Zsalt._logging.handlersrrrrr	Zsalt._logging.mixinsr
Zsalt.exceptionsrZsalt.utils.ctxrZsalt.utils.immutabletypesr
rZsalt.utils.textformatrr(r%r!r r#r"r�rZLOG_VALUES_TO_LEVELSrF�sortedZSORTED_LEVEL_NAMES�compileriZDFLT_LOG_FMT_JIDr�r�r�r�r9r4rErKrQ�getLoggerClassr�rRr�r�r�r�r�rbr�r�Zpip._internal.utils._logZ	_internalr�r�Zpip_log_module�ImportError�setLoggerClass�addLevelNamer�verboser`rar�r�rrAr�r�r�r�r�r�r�r�r�r�rrr�r
rrrrrr��
__stderr__�format_exceptionr(�
excepthookrrrr�<module>s(



�
�������*

^
	

'�





4

�7


F	(



�
1