HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //proc/self/root/lib/python3/dist-packages/uaclient/__pycache__/log.cpython-38.pyc
U

��Jh��@s�ddlZddlZddlZddlZddlmZddlmZmZm	Z	m
Z
ddlmZm
Z
mZmZddlmZGdd�dej�ZGdd	�d	ej�ZGd
d�dej�Zed�d
d�Zed�dd�Ze	ed�dd�Zdd�Ze
eefed�dd�Zdd�ZdS)�N)�OrderedDict)�Any�Dict�List�Union)�defaults�secret_manager�system�util)�UAConfigc@s eZdZdZejd�dd�ZdS)�RegexRedactionFilter�,A logging filter to redact confidential info��recordcCst�t|j��|_dS�NT)r
Zredact_sensitive_logs�str�msg��selfr�r�./usr/lib/python3/dist-packages/uaclient/log.py�filterszRegexRedactionFilter.filterN��__name__�
__module__�__qualname__�__doc__�logging�	LogRecordrrrrrrsrc@s eZdZdZejd�dd�ZdS)�KnownSecretRedactionFilterr
rcCstj�t|j��|_dSr)rZsecretsZredact_secretsrrrrrrrsz!KnownSecretRedactionFilter.filterNrrrrrrsrc@s.eZdZdZdZdZdZeje	d�dd�Z
dS)	�JsonArrayFormatterzYJson Array Formatter for our logging mechanism
    Custom made for Pro logging needs
    z%Y-%m-%dT%H:%M:%Sz%s.%03d)�asctimeZ	levelname�nameZfuncName�lineno�message)r�returncCs�|��|_|�|�|_i}|jr0|�|j�|d<|�d�sJ|jrJ|j|d<|jr`|�	|j�|d<|j
�d�}|r�t|t�r�|�
|�t�}|jD]}|j
�|�}|||<q�||d<t�t|����S)N�exc_info�
stack_info�extra)Z
getMessager$Z
formatTimer!r&ZformatException�getZexc_textr'ZformatStack�__dict__�
isinstance�dict�updater�required_fields�json�dumps�list�values)rrZextra_message_dictr(Zlocal_log_recordZfield�valuerrr�format,s,
�
�


zJsonArrayFormatter.formatN)rrrrZdefault_time_formatZdefault_msec_formatr.rrrr4rrrrr s
	r )r%cCst��rt�jSt�SdS)z\
    Gets the correct log_file path,
    adjusting for whether the user is root or not.
    N)r
�we_are_currently_rootr�log_file�get_user_log_filerrrr�get_user_or_root_log_file_pathJsr8cCstj�t��d�S)z/Gets the correct user log_file storage location�ubuntu-pro.log)�os�path�joinr	Zget_user_cache_dirrrrrr7Usr7cCsHt�d�}g}|D]0}tj�d|dtjd�}tj�|�r|�|�q|S)z|Gets all the log files for the users in the system

    Returns a list of all user log files in their home directories.
    z/homez.cacher9)r:�listdirr;r<rZUSER_CACHE_SUBDIR�isfile�append)Zuser_directoriesZ	log_filesZuser_directoryZ	user_pathrrr�get_all_user_log_filesZs
�r@cCs\t�d�}|�tj�t��}|�t��|�tj�|�t��|�t	��|�
|�dS)N�	ubuntupro)r�	getLogger�setLevel�INFOZ
StreamHandler�setFormatterr �	addFilterrr�
addHandler)�loggerZconsole_handlerrrr�setup_journald_loggingns
rI)�	log_levelr6cCs�t|t�r|��}t��s t�}t�d�}|�|�g|_	t
�|�}|��sh|j
jddd�|jdd�t�|�}|�t��|�|�|�t��|�t��|�|�dS)zoSetup logging to log_file

    If run as non-root then log_file is replaced with a user-specific log file.
    rAT)�parents�exist_oki�)�modeN)r+r�upperr
r5r7rrBrCZhandlers�pathlib�Path�exists�parent�mkdirZtouchZFileHandlerrEr rFrrrG)rJr6rHZ
log_file_pathZfile_handlerrrr�setup_cli_loggingys"





rTcKsd|iS)z�
    A helper for passing extra fields to log statements.
    Usage:
    LOG.info("message string", extra=log.extra(field=something_relevant))
    r(r)�kwargsrrrr(�sr()r/rr:rO�collectionsr�typingrrrrZuaclientrrr	r
Zuaclient.configrZFilterrrZ	Formatterr rr8r7r@rI�intrTr(rrrr�<module>s .!