Ë
    GKÕi™  ã                   ó:  — d dl Z d dlZd dlZd dlZd dlmZ d dlmZmZm	Z	m
Z
 d dlmZmZmZmZ d dlmZ  G d„ dej$                  «      Z G d„ d	ej$                  «      Z G d
„ dej*                  «      Zdefd„Zdefd„Zde	e   fd„Zd„ Zde
eef   defd„Zd„ Zy)é    N)ÚOrderedDict)ÚAnyÚDictÚListÚUnion)ÚdefaultsÚsecret_managerÚsystemÚutil)ÚUAConfigc                   ó0   — e Zd ZdZdej
                  fd„Zy)ÚRegexRedactionFilterú,A logging filter to redact confidential infoÚrecordc                 ó^   — t        j                  t        |j                  «      «      |_        y©NT)r   Úredact_sensitive_logsÚstrÚmsg©Úselfr   s     ú./usr/lib/python3/dist-packages/uaclient/log.pyÚfilterzRegexRedactionFilter.filter   s   € Ü×/Ñ/´°F·J±J³Ó@ˆŒ
Øó    N©Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚloggingÚ	LogRecordr   © r   r   r   r      ó   „ Ù6ð˜W×.Ñ.ô r   r   c                   ó0   — e Zd ZdZdej
                  fd„Zy)ÚKnownSecretRedactionFilterr   r   c                 ór   — t         j                  j                  t        |j                  «      «      |_        yr   )r	   ÚsecretsÚredact_secretsr   r   r   s     r   r   z!KnownSecretRedactionFilter.filter   s%   € Ü#×+Ñ+×:Ñ:¼3¸v¿z¹z»?ÓKˆŒ
Ør   Nr   r"   r   r   r%   r%      r#   r   r%   c                   ó@   — e Zd ZdZdZdZdZdej                  de	fd„Z
y)	Ú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   Úreturnc                 ó°  — |j                  «       |_        | j                  |«      |_        i }|j                  r| j                  |j                  «      |d<   |j                  d«      s|j                  r|j                  |d<   |j                  r| j                  |j                  «      |d<   |j                  j                  d«      }|r!t        |t        «      r|j                  |«       t        «       }| j                  D ]"  }|j                  j                  |«      }|||<   Œ$ ||d<   t!        j"                  t%        |j'                  «       «      «      S )NÚexc_infoÚ
stack_infoÚextra)Ú
getMessager0   Ú
formatTimer+   r3   ÚformatExceptionÚgetÚexc_textr4   ÚformatStackÚ__dict__Ú
isinstanceÚdictÚupdater   Úrequired_fieldsÚjsonÚdumpsÚlistÚvalues)r   r   Úextra_message_dictr5   Úlocal_log_recordÚfieldÚvalues          r   ÚformatzJsonArrayFormatter.format,   s2  € Ø×*Ñ*Ó,ˆŒØŸ™¨Ó0ˆŒàÐØ�?Š?Ø-1×-AÑ-AØ—‘ó.Ð˜zÑ*ð "×%Ñ% jÔ1°f·o²oØ-3¯_©_Ð˜zÑ*Ø×ÒØ/3×/?Ñ/?Ø×!Ñ!ó0Ð˜|Ñ,ð —‘×#Ñ# GÓ,ˆÙ”Z ¤tÔ,Ø×%Ñ% eÔ,ô '›=Ðà×)Ñ)ò 	,ˆEØ—O‘O×'Ñ'¨Ó.ˆEØ&+Ð˜UÒ#ð	,ð %7Ð˜Ñ!Ü�z‰zœ$Ð/×6Ñ6Ó8Ó9Ó:Ð:r   N)r   r   r   r   Údefault_time_formatÚdefault_msec_formatr@   r    r!   r   rI   r"   r   r   r*   r*      s5   „ ñð .ÐØ#Ðð€Oð;˜W×.Ñ.ð ;°3ô ;r   r*   r1   c                  óf   — t        j                  «       rt        «       j                  S t	        «       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_filer"   r   r   Úget_user_or_root_log_file_pathrP   J   s'   € ô
 ×!Ñ!Ô#Ü‹z×"Ñ"Ð"ä Ó"Ð"r   c                  óf   — t         j                  j                  t        j                  «       d«      S )z/Gets the correct user log_file storage locationúubuntu-pro.log)ÚosÚpathÚjoinr
   Úget_user_cache_dirr"   r   r   rO   rO   U   s!   € ä�7‰7�<‰<œ×1Ñ1Ó3Ð5EÓFÐFr   c                  ó  — t        j                  d«      } g }| D ]d  }t         j                  j                  d|dt        j
                  d«      }t         j                  j                  |«      sŒT|j                  |«       Œf |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.cacherR   )rS   ÚlistdirrT   rU   r   ÚUSER_CACHE_SUBDIRÚisfileÚappend)Úuser_directoriesÚ	log_filesÚuser_directoryÚ	user_paths       r   Úget_all_user_log_filesr`   Z   sv   € ô
 —z‘z 'Ó*ÐØ€IØ*ò 	(ˆÜ—G‘G—L‘LØØØÜ×&Ñ&Øó
ˆ	ô �7‰7�>‰>˜)Õ$Ø×Ñ˜YÕ'ð	(ð Ðr   c                  óŠ  — t        j                  d«      } | j                  t         j                  «       t        j                  «       }|j                  t        «       «       |j                  t         j                  «       |j                  t        «       «       |j                  t        «       «       | j                  |«       y )NÚ	ubuntupro)r    Ú	getLoggerÚsetLevelÚINFOÚStreamHandlerÚsetFormatterr*   Ú	addFilterr   r%   Ú
addHandler)ÚloggerÚconsole_handlers     r   Úsetup_journald_loggingrl   n   s†   € Ü×Ñ˜{Ó+€FØ
‡O�O”G—L‘LÔ!Ü×+Ñ+Ó-€OØ× Ñ Ô!3Ó!5Ô6Ø×ÑœWŸ\™\Ô*Ø×ÑÔ2Ó4Ô5Ø×ÑÔ8Ó:Ô;Ø
×Ñ�oÕ&r   Ú	log_levelrN   c                 ó†  — t        | t        «      r| j                  «       } t        j                  «       s
t        «       }t        j                  d«      }|j                  | «       g |_	        t        j                  |«      }|j                  «       s/|j                  j                  dd¬«       |j                  d¬«       t        j                   |«      }|j#                  t%        «       «       |j                  | «       |j'                  t)        «       «       |j'                  t+        «       «       |j-                  |«       y)zoSetup logging to log_file

    If run as non-root then log_file is replaced with a user-specific log file.
    rb   T)ÚparentsÚexist_oki   )ÚmodeN)r=   r   Úupperr   rM   rO   r    rc   rd   ÚhandlersÚpathlibÚPathÚexistsÚparentÚmkdirÚtouchÚFileHandlerrg   r*   rh   r   r%   ri   )rm   rN   rj   Úlog_file_pathÚfile_handlers        r   Úsetup_cli_loggingr}   y   sý   € ô �)œSÔ!Ø—O‘OÓ%ˆ	ô ×%Ñ%Ô'Ü$Ó&ˆä×Ñ˜{Ó+€FØ
‡O�O�IÔð €F„Oô —L‘L Ó*€MØ×ÑÔ!Ø×Ñ×"Ñ"¨4¸$Ð"Ô?Ø×Ñ ÐÔ'Ü×&Ñ& xÓ0€LØ×ÑÔ0Ó2Ô3Ø×Ñ˜)Ô$Ø×ÑÔ/Ó1Ô2Ø×ÑÔ5Ó7Ô8à
×Ñ�lÕ#r   c                  ó
   — d| iS )z“
    A helper for passing extra fields to log statements.
    Usage:
    LOG.info("message string", extra=log.extra(field=something_relevant))
    r5   r"   )Úkwargss    r   r5   r5   š   s   € ð �VÐÐr   )rA   r    rS   rt   Úcollectionsr   Útypingr   r   r   r   Úuaclientr   r	   r
   r   Úuaclient.configr   ÚFilterr   r%   Ú	Formatterr*   r   rP   rO   r`   rl   Úintr}   r5   r"   r   r   ú<module>r‡      s¦   ðÛ Û Û 	Û Ý #ß )Ó )ç ;Ó ;Ý $ô˜7Ÿ>™>ô ô §¡ô ô+;˜×*Ñ*ô +;ð\#¨ó #ðG˜3ó Gð
  S¡	ó ò('ð$  s¨C x¡ð $¸Có $óBr   