+
    g                     (   ^ RI t ^ RIt^ RIt^ RIt^ RIHt ^ RIHtHtH	t	H
t
 ^ RIHtHtHtHt ^ RIHt  ! R R]P$                  4      t ! R R	]P$                  4      t ! R
 R]P*                  4      tR R ltR R ltR R ltR tR R ltR tR# )    N)OrderedDict)AnyDictListUnion)defaultssecret_managersystemutil)UAConfigc                   6   a  ] tR t^t o RtV 3R lR ltRtV tR# )RegexRedactionFilter,A logging filter to redact confidential infoc                4   < V ^8  d   QhRS[ P                  /#    recordlogging	LogRecord)format__classdict__s   "./usr/lib/python3/dist-packages/uaclient/log.py__annotate__!RegexRedactionFilter.__annotate__         W..     c                b    \         P                  ! \        VP                  4      4      Vn        R # T)r   redact_sensitive_logsstrmsgselfr   s   &&r   filterRegexRedactionFilter.filter   s    //FJJ@
r    N__name__
__module____qualname____firstlineno____doc__r%   __static_attributes____classdictcell__r   s   @r   r   r           6 r   r   c                   6   a  ] tR t^t o RtV 3R lR ltRtV tR# )KnownSecretRedactionFilterr   c                4   < V ^8  d   QhRS[ P                  /# r   r   )r   r   s   "r   r   'KnownSecretRedactionFilter.__annotate__   r   r   c                t    \         P                  P                  \        VP                  4      4      Vn        R # r   )r	   secretsredact_secretsr!   r"   r#   s   &&r   r%   !KnownSecretRedactionFilter.filter   s%    #++::3vzz?K
r   r'   Nr(   r0   s   @r   r3   r3      r1   r   r3   c                   B   a  ] tR t^t o RtRtRtRtV 3R lR ltRt	V t
R# )	JsonArrayFormatterzQJson Array Formatter for our logging mechanism
Custom made for Pro logging needs
z%Y-%m-%dT%H:%M:%Sz%s.%03dc                :   < V ^8  d   QhRS[ P                  RS[/# )r   r   return)r   r   r!   )r   r   s   "r   r   JsonArrayFormatter.__annotate__,   s!     ; ;W.. ;3 ;r   c                   VP                  4       Vn        V P                  V4      Vn        / pVP                  '       d   V P                  VP                  4      VR &   VP                  R 4      '       g"   VP                  '       d   VP                  VR &   VP                  '       d   V P                  VP                  4      VR&   VP                  P                  R4      pV'       d(   \        V\        4      '       d   VP                  V4       \        4       pV P                   F"  pVP                  P                  V4      pWdV&   K$  	  W$R&   \         P"                  ! \%        VP'                  4       4      4      # )exc_info
stack_infoextra)
getMessagemessage
formatTimeasctimer@   formatExceptiongetexc_textrA   formatStack__dict__
isinstancedictupdater   required_fieldsjsondumpslistvalues)r$   r   extra_message_dictrB   local_log_recordfieldvalues   &&     r   r   JsonArrayFormatter.format,   s4   **,0???-1-A-A.z* "%%j11fooo-3__z*/3/?/?!!0|, ##G,Zt,,%%e, '=))EOO''.E&+U# * %7!zz$/6689::r   r'   N)rF   	levelnamenamefuncNamelinenorD   )r)   r*   r+   r,   r-   default_time_formatdefault_msec_formatrO   r   r.   r/   r0   s   @r   r;   r;      s)      .#O; ;r   r;   c                $    V ^8  d   QhR\         /# r   r=   r!   )r   s   "r   r   r   J   s     # # #r   c                 t    \         P                  ! 4       '       d   \        4       P                  # \	        4       # )zP
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_pathrf   J   s*    
 !!##z""" ""r   c                $    V ^8  d   QhR\         /# r`   ra   )r   s   "r   r   r   U   s     G G3 Gr   c                 h    \         P                  P                  \        P                  ! 4       R4      # )z/Gets the correct user log_file storage locationubuntu-pro.log)ospathjoinr
   get_user_cache_dirr'   r   r   re   re   U   s!    77<<1135EFFr   c                :    V ^8  d   QhR\         \        ,          /# r`   )r   r!   )r   s   "r   r   r   Z   s      S	 r   c                    \         P                  ! R4      p . pV  Fl  p\         P                  P                  RVR\        P
                  R4      p\         P                  P                  V4      '       g   K[  VP                  V4       Kn  	  V# )ztGets 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   listdirrk   rl   r   USER_CACHE_SUBDIRisfileappend)user_directories	log_filesuser_directory	user_paths       r   get_all_user_log_filesrx   Z   st    
 zz'*I*GGLL&&
	 77>>)$$Y' + r   c                     \         P                  ! R 4      p V P                  \         P                  4       \         P                  ! 4       pVP                  \        4       4       VP                  \         P                  4       VP                  \        4       4       VP                  \        4       4       V P                  V4       R# )	ubuntuproN)r   	getLoggersetLevelINFOStreamHandlersetFormatterr;   	addFilterr   r3   
addHandler)loggerconsole_handlers     r   setup_journald_loggingr   n   s    {+F
OOGLL!++-O  !3!56W\\*2458:;
o&r   c                R    V ^8  d   QhR\         \        \        3,          R\        /# )r   	log_levelrd   )r   r!   int)r   s   "r   r   r   y   s"     $ $sCx $C $r   c                   \        V \        4      '       d   V P                  4       p \        P                  ! 4       '       g   \        4       p\        P                  ! R4      pVP                  V 4       . Vn	        \        P                  ! V4      pVP                  4       '       g0   VP                  P                  RRR7       VP                  RR7       \        P                   ! V4      pVP#                  \%        4       4       VP                  V 4       VP'                  \)        4       4       VP'                  \+        4       4       VP-                  V4       R# )zgSetup logging to log_file

If run as non-root then log_file is replaced with a user-specific log file.
rz   T)parentsexist_oki  )modeN)rL   r!   upperr   rc   re   r   r{   r|   handlerspathlibPathexistsparentmkdirtouchFileHandlerr   r;   r   r   r3   r   )r   rd   r   log_file_pathfile_handlers   &&   r   setup_cli_loggingr   y   s    )S!!OO%	 %%''$&{+F
OOI FO LL*M!!""4$"?'&&x0L023)$/12578
l#r   c                 
    RV /# )z
A helper for passing extra fields to log statements.
Usage:
LOG.info("message string", extra=log.extra(field=something_relevant))
rB   r'   )kwargss   ,r   rB   rB      s     Vr   )rP   r   rj   r   collectionsr   typingr   r   r   r   uaclientr   r	   r
   r   uaclient.configr   Filterr   r3   	Formatterr;   rf   re   rx   r   r   rB   r'   r   r   <module>r      sv      	  # ) ) ; ; $7>>  +;** +;\#G
('$Br   