
    Cj>                    &   % S r SSKJr  SSKrSSKrSSKrSSKrSSKJr  SSK	J
r
  SSKJr  \(       a  SSKJr  \" SSS	9rS
\S'   \" SSS	9rS
\S'   SS jrSS jr " S S\R(                  5      rSrSrSrS\S'   SrSrS\S'   SS jrSS.S S jjrg)!zPer-scan logging setup.    )annotationsN)
ContextVar)Path)TYPE_CHECKING)Callablestrix_scan_id)defaultzContextVar[str | None]_SCAN_IDstrix_agent_id	_AGENT_IDc                .    [         R                  U 5        g)zJSet the scan_id seen on every log record from this point in the task tree.N)r
   set)scan_ids    i/home/rurouni/.local/share/pipx/venvs/strix-agent/lib/python3.13/site-packages/strix/telemetry/logging.pyset_scan_idr      s    LL    c                .    [         R                  U 5        g)zSet or clear the agent_id seen on every log record from this point.

``None`` clears (renders as ``-`` in the log line). Mutations are
isolated to the current asyncio task and tasks created from it after
the call.
N)r   r   )agent_ids    r   set_agent_idr      s     MM(r   c                      \ rS rSrSS jrSrg)_StrixContextFilter%   c                    [         R                  5       =(       d    SUl        [        R                  5       =(       d    SUl        g)N-T)r
   getr   r   r   )selfrecords     r   filter_StrixContextFilter.filter&   s)    !.3#--/0Sr    N)r   zlogging.LogRecordreturnbool)__name__
__module____qualname____firstlineno__r   __static_attributes__r    r   r   r   r   %   s    r   r   zV%(asctime)s.%(msecs)03d %(levelname)-7s %(scan_id)s %(agent_id)s %(name)s: %(message)sz%Y-%m-%d %H:%M:%S)httpxhttpcoreurllib3litellmopenai	anthropicztuple[str, ...]_NOISY_LIBS_strix_scan_handler)strixzopenai.agents_TRACKED_ROOTSc                 |   [         R                  " [        5         SSKn U R                  nUR                  5         SSS5        [        R                  " S5      R                  [        R                  5        S[        R                  " S5      l
        [        R                  " S[        SS9  g! , (       d  f       Nw= f)z?Quiet dependency logging/warnings that obscure Strix scan logs.r   NasyncioFignore)categorymodule)
contextlibsuppress	Exceptionr+   _logging_disable_debugginglogging	getLoggersetLevelCRITICAL	propagatewarningsfilterwarningsRuntimeWarning)r+   litellm_loggings     r   configure_dependency_loggingrE   C   s~    			Y	'!****,	 
( i ))'*:*:;-2Gi *H~iP 
(	's   !B--
B;)debugc                 ^
 [        5         UcG  [        R                  R                  S5      =(       d    SR	                  5       R                  5       S;   nU R                  SSS9  U S-  n[        R                  " [        [        S9n[        5       n[        R                  " USS	S
9nUR                  [        R                  5        UR                  U5        UR!                  U5        [#        U[$        S5        [        R&                  " 5       nUR                  U(       a  [        R                  O[        R(                  5        UR                  U5        UR!                  U5        [#        U[$        S5        [*         Vs/ s H  n[        R,                  " U5      PM     snm
T
 HK  nUR                  [        R                  5        UR/                  U5        UR/                  U5        SUl        MM     [2         H6  n[        R,                  " U5      R                  [        R4                  5        M8     SU
4S jjn	U	$ s  snf )ur  Attach scan-scoped handlers; return a teardown callable.

Args:
    run_dir: Per-scan output directory. ``{run_dir}/strix.log`` is
        created if missing and opened append-mode (so re-runs of the
        same scan_id concatenate cleanly).
    debug: When ``True``, stderr handler runs at DEBUG instead of
        ERROR. ``None`` (default) reads ``STRIX_DEBUG`` env: ``1`` /
        ``true`` / ``yes`` / ``on`` enables debug.

Returns:
    A no-arg callable that flushes/closes/removes the handlers this
    call attached. Idempotent — calling twice is a no-op the second
    time. Safe to call from a ``finally`` block.
STRIX_DEBUG >   1onyestrueT)parentsexist_okz	strix.log)datefmtazutf-8)modeencodingFc                 L  > T H  n [        U R                  5       Ho  n[        U[        S5      (       d  M  U R	                  U5        [
        R                  " [        5         UR                  5         UR                  5         S S S 5        Mq     M     g ! , (       d  f       M  = f)NF)
listhandlersgetattr_HANDLER_TAGremoveHandlerr7   r8   r9   flushclose)trackedhandlertracked_loggerss     r   	_teardown%setup_scan_logging.<locals>._teardown   sp    &G 0 017L%88))'2#,,Y7 87 2 ' 87s   "!B
B#r!   None)rE   osenvironr   striplowermkdirr<   	Formatter_FORMAT_DATEFMTr   FileHandlerr>   DEBUGsetFormatter	addFiltersetattrrX   StreamHandlerERRORr1   r=   
addHandlerr@   r.   WARNING)run_dirrF   log_path	formattercontext_filterfile_handlerstream_handlernamer\   r_   r^   s             @r   setup_scan_loggingr{   P   s     !"}.4";;=CCE J
 
 MM$M.$H!!'8<I(*N&&xcGLL'--(i(>*L,-**,NUGMMF	*^,NL$/;IJ>4w((.>JO"'<(>*!	 # $((9 ( ' Ks     H>)r   strr!   rb   )r   z
str | Noner!   rb   ra   )rt   r   rF   zbool | Noner!   zCallable[[], None])__doc__
__future__r   r7   r<   rc   rA   contextvarsr   pathlibr   typingr   collections.abcr   r
   __annotations__r   r   r   Filterr   ri   rj   r.   rX   r1   rE   r{   r    r   r   <module>r      s     "   	  "    ( $.ot#L
  L$./?$N	! N
'..  c
 _  % #= <
Q ?C ? ?r   