+
    ib                         R t ^ RIt^ RIt^ RIHt ^ RIHt ^ RIHt ^ RI	H
t
 RsRtRtRtR	RR
RRRRRRRRR/R R lltR R ltR R ltR tR# )u  Centralized logging setup for Hermes Agent.

Provides a single ``setup_logging()`` entry point that both the CLI and
gateway call early in their startup path.  All log files live under
``~/.hermes/logs/`` (profile-aware via ``get_hermes_home()``).

Log files produced:
    agent.log   — INFO+, all agent/tool/session activity (the main log)
    errors.log  — WARNING+, errors and warnings only (quick triage)

Both files use ``RotatingFileHandler`` with ``RedactingFormatter`` so
secrets are never written to disk.
N)RotatingFileHandler)Path)Optional)get_hermes_homeFz/%(asctime)s %(levelname)s %(name)s: %(message)sz4%(asctime)s - %(name)s - %(levelname)s - %(message)shermes_home	log_levelmax_size_mbbackup_countmodeforcec                    V ^8  d   QhR\         \        ,          R\         \        ,          R\         \        ,          R\         \        ,          R\         \        ,          R\        R\        /# )   r   r   r   r	   r
   r   return)r   r   strintbool)formats   "+/home/ubuntu/hermes-agent/hermes_logging.py__annotate__r   3   sm     [ [$[ }[ #	[
 3-[ 3-[ [ 
[    c           
        \         '       d&   V'       g   T ;'       g    \        4       pVR,          # T ;'       g    \        4       pVR,          pVP                  RRR7       \        4       w  rp
T;'       g    T;'       g    RP	                  4       p\        \        V\        P                  4      pT;'       g    T	;'       g    ^R,          R,          pT;'       g    T
;'       g    ^p^ RIH	p \        P                  ! 4       p\        VVR,          VVVV! \        4      R7       \        VVR	,          \        P                  R
^V! \        4      R7       VP                  \        P                  8X  g   VP                  V8  d   VP!                  V4       \"         F6  p\        P                  ! V4      P!                  \        P                  4       K8  	  Rs V# )u  Configure the Hermes logging subsystem.

Safe to call multiple times — the second call is a no-op unless
*force* is ``True``.

Parameters
----------
hermes_home
    Override for the Hermes home directory.  Falls back to
    ``get_hermes_home()`` (profile-aware).
log_level
    Minimum level for the ``agent.log`` file handler.  Accepts any
    standard Python level name (``"DEBUG"``, ``"INFO"``, ``"WARNING"``).
    Defaults to ``"INFO"`` or the value from config.yaml ``logging.level``.
max_size_mb
    Maximum size of each log file in megabytes before rotation.
    Defaults to 5 or the value from config.yaml ``logging.max_size_mb``.
backup_count
    Number of rotated backup files to keep.
    Defaults to 3 or the value from config.yaml ``logging.backup_count``.
mode
    Hint for the caller context: ``"cli"``, ``"gateway"``, ``"cron"``.
    Currently used only for log format tuning (gateway includes PID).
force
    Re-run setup even if it has already been called.

Returns
-------
Path
    The ``logs/`` directory where files are written.
logsTparentsexist_okINFOi   RedactingFormatterz	agent.log)level	max_bytesr	   	formatterz
errors.logi    )_logging_initializedr   mkdir_read_logging_configuppergetattrloggingr   agent.redactr   	getLogger_add_rotating_handler_LOG_FORMATWARNINGr   NOTSETsetLevel_NOISY_LOGGERS)r   r   r   r	   r
   r   homelog_dir	cfg_levelcfg_max_size
cfg_backup
level_namer   r   backupsr   rootnames   $$$$$$            r   setup_loggingr8   3   s   R E//o/f}++/+DVmGMM$M. +?*@'IZ22y22F99;JGZ6E1111T9D@I--j--AG 0D +$[1 ,oo!$[1 zzW^^#tzzE'9e $((9   Nr   c                    V ^8  d   QhRR/# )r   r   N )r   s   "r   r   r      s     ; ;t ;r   c                 6   ^ RI Hp  \        P                  ! 4       pVP                   FS  p\        V\        P                  4      '       g   K%  \        V\        4      '       d   K=  \        VRR4      '       g   KR   R# 	  \        P                  ! 4       pVP                  \        P                  4       VP                  V ! \        RR7      4       RVn        VP                  V4       VP                  \        P                  8  d    VP                  \        P                  4       \          F6  p\        P                  ! V4      P                  \        P"                  4       K8  	  \        P                  ! R4      P                  \        P$                  4       R# )	zEnable DEBUG-level console logging for ``--verbose`` / ``-v`` mode.

Called by ``AIAgent.__init__()`` when ``verbose_logging=True``.
r   _hermes_verboseFNz%H:%M:%S)datefmtTz
rex-deploy)r'   r   r&   r(   handlers
isinstanceStreamHandlerr   r%   r-   DEBUGsetFormatter_LOG_FORMAT_VERBOSEr<   
addHandlerr   r.   r+   r   )r   r6   hhandlerr7   s        r   setup_verbose_loggingrG      s   
 0D ]]a..//
1FY8Z8Zq+U33 
 ##%GW]]#+,?TU"GOOG zzGMM!gmm$ $((9  l#,,W\\:r   c                    V ^8  d   QhR\         P                  R\        R\        R\        R\        R\         P                  RR/# )	r   loggerpathr   r   r	   r    r   N)r&   Loggerr   r   	Formatter)r   s   "r   r   r      sX      NN
 	
      
r   c                  VP                  4       pV P                   FG  p\        V\        4      '       g   K  \	        \        VRR4      4      P                  4       V8X  g   KF   R# 	  VP                  P                  RRR7       \        \        V4      W4R7      pVP                  V4       VP                  V4       V P                  V4       R# )zxAdd a ``RotatingFileHandler`` to *logger*, skipping if one already
exists for the same resolved file path (idempotent).
baseFilename NTr   )maxBytesbackupCount)resolver>   r?   r   r   r%   parentr"   r   r-   rB   rD   )	rI   rJ   r   r   r	   r    resolvedexistingrF   s	   &&$$$$   r   r)   r)      s     ||~HOOx!455WX~r:;CCEQ $ 	KKdT2!D	IG U#
gr   c                     ^ RI p \        4       R,          pVP                  4       '       d   \        VRRR7      ;_uu_ 4       pV P	                  V4      ;'       g    / pRRR4       XP                  R/ 4      p\        V\        4      '       d3   VP                  R4      VP                  R4      VP                  R	4      3# R
#   + '       g   i     Ll; i  \         d     L"i ; i)u}   Best-effort read of ``logging.*`` from config.yaml.

Returns ``(level, max_size_mb, backup_count)`` — any may be ``None``.
Nzconfig.yamlrzutf-8)encodingr&   r   r   r	   )NNN)	yamlr   existsopen	safe_loadgetr?   dict	Exception)rY   config_pathfcfglog_cfgs        r   r#   r#      s    
%'-7k399QnnQ'--2 :ggi,G'4((KK(KK.KK/   :9  s+   AC CA!C C	C C$#C$)openaizopenai._base_clienthttpxhttpcoreasynciohpackzhpack.hpackgrpcmodalurllib3zurllib3.connectionpool
websocketscharset_normalizermarkdown_it)__doc__r&   oslogging.handlersr   pathlibr   typingr   hermes_constantsr   r!   r*   rC   r.   r8   rG   r)   r#   r:   r   r   <module>ru      s     	 0   ,
   @L $["&[  $[ "&	[
 #'[ [ [|;H:r   