CasperSecurity

Current Path : /lib/python3/dist-packages/uaclient/__pycache__/
Upload File :
Current File : //lib/python3/dist-packages/uaclient/__pycache__/log.cpython-310.pyc

o

��Jh��@s�ddlZddlZddlZddlZddlmZddlmZmZm	Z	m
Z
ddlmZm
Z
mZmZddlmZGdd�dej�ZGdd	�d	ej�ZGd
d�dej�Zdefd
d�Zdefdd�Zde	efdd�Zdd�Zde
eefdefdd�Zdd�ZdS)�N)�OrderedDict)�Any�Dict�List�Union)�defaults�secret_manager�system�util)�UAConfigc@� eZdZdZdejfdd�ZdS)�RegexRedactionFilter�,A logging filter to redact confidential info�recordcCst�t|j��|_dS�NT)r
�redact_sensitive_logs�str�msg��selfr�r�./usr/lib/python3/dist-packages/uaclient/log.py�filterszRegexRedactionFilter.filterN��__name__�
__module__�__qualname__�__doc__�logging�	LogRecordrrrrrr
�r
c@r)�KnownSecretRedactionFilterrrcCstj�t|j��|_dSr)r�secrets�redact_secretsrrrrrrrsz!KnownSecretRedactionFilter.filterNrrrrrr!r r!c@s0eZdZdZdZdZdZdejde	fdd�Z
d	S)
�JsonArrayFormatterzYJson Array Formatter for our logging mechanism
    Custom made for Pro logging needs
    z%Y-%m-%dT%H:%M:%Sz%s.%03d)�asctime�	levelname�name�funcName�lineno�messager�returncCs�|��|_|�|�|_i}|jr|�|j�|d<|�d�s%|jr%|j|d<|jr0|�	|j�|d<|j
�d�}|rBt|t�rB|�
|�t�}|jD]}|j
�|�}|||<qH||d<t�t|����S)N�exc_info�
stack_info�extra)�
getMessager*�
formatTimer%r,�formatException�get�exc_textr-�formatStack�__dict__�
isinstance�dict�updater�required_fields�json�dumps�list�values)rr�extra_message_dictr.�local_log_record�field�valuerrr�format,s,
�
�


zJsonArrayFormatter.formatN)rrrr�default_time_format�default_msec_formatr9rrrrBrrrrr$s	r$r+cCst��rt�jSt�S)z\
    Gets the correct log_file path,
    adjusting for whether the user is root or not.
    )r
�we_are_currently_rootr�log_file�get_user_log_filerrrr�get_user_or_root_log_file_pathJsrHcCstj�t��d�S)z/Gets the correct user log_file storage location�ubuntu-pro.log)�os�path�joinr	�get_user_cache_dirrrrrrGUsrGcCsHt�d�}g}|D]}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.cacherI)rJ�listdirrKrLr�USER_CACHE_SUBDIR�isfile�append)�user_directories�	log_files�user_directory�	user_pathrrr�get_all_user_log_filesZs
�
�rVcCs\t�d�}|�tj�t��}|�t��|�tj�|�t��|�t	��|�
|�dS)N�	ubuntupro)r�	getLogger�setLevel�INFO�
StreamHandler�setFormatterr$�	addFilterr
r!�
addHandler)�logger�console_handlerrrr�setup_journald_loggingns
ra�	log_levelrFcCs�t|t�r	|��}t��st�}t�d�}|�|�g|_	t
�|�}|��s4|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.
    rWT)�parents�exist_oki�)�modeN)r6r�upperr
rErGrrXrY�handlers�pathlib�Path�exists�parent�mkdir�touch�FileHandlerr\r$r]r
r!r^)rbrFr_�
log_file_path�file_handlerrrr�setup_cli_loggingys"





rqcKsd|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:rrJrh�collectionsr�typingrrrr�uaclientrrr	r
�uaclient.configr�Filterr
r!�	Formatterr$rrHrGrVra�intrqr.rrrr�<module>s".!
Hacker Blog, Shell İndir, Sql İnjection, XSS Attacks, LFI Attacks, Social Hacking, Exploit Bot, Proxy Tools, Web Shell, PHP Shell, Alfa Shell İndir, Hacking Training Set, DDoS Script, Denial Of Service, Botnet, RFI Attacks, Encryption
Telegram @BIBIL_0DAY