a
    6iE	                     @   sT   d Z ddlZddlZddlmZ ddlmZ G dd deZG dd dZe Z	dS )	z1Simple logging to stdout the same way Proton does    N)Enum)Pathc                   @   s$   e Zd ZdZdZdZdZdZdZdS )LogLevelz0Enum and mapping (level -> color) for log levelsz[0mz[34mz[33mz[31mz[35mN)	__name__
__module____qualname____doc__RESETINFOWARNCRITDEBUG r   r   _/home/james-whalen/.local/share/Steam/compatibilitytools.d/GE-Proton10-32/protonfixes/logger.pyr      s   r   c                   @   s   e Zd ZdZde  dZeej	
 Zeejde d Zed Zzejddd ed	 ZW n ey   ed
ZY n0 eeeedddZeeddddZedejfeeddddZeeddddZeeddddZeeddddZeeddddZdS )LogzLog to stderr for steam dumpszProtonFixes[]ZXDG_CACHE_HOMEz.cachezumu-protonfixesT)parentsexist_okzprotonfixes_test.logz/tmp/protonfixes_test.log)msglevelreturnc                 C   s(   | j s
|S |j}tjj}| | | S )N)is_ttyvaluer   r	   )clsr   r   Zcolorresetr   r   r   Z
__colorize$   s
    zLog.__colorizeN)r   r   c                 C   s   |  | dS )z-Allows the Log instance to be called directlyN)logr   r   r   r   r   __call__,   s    zLog.__call__ c                 C   s   t | | j d|j d| |tjdd t| jdddd0}t | j d|j d| |d	 W d
   n1 st0    Y  d
S )z7Prints the log message to stdout the same way as Proton z: T)fileflusha   zutf-8)	bufferingencoding)r    N)print_Log__colorizepfxnamesysstderropenlogfile)r   r   r   Ztestfiler   r   r   r   1   s    zLog.logc                 C   s   |  |tj dS )z"Wrapper for printing info messagesN)r   r   r
   r   r   r   r   info?   s    zLog.infoc                 C   s   |  |tj dS )z%Wrapper for printing warning messagesN)r   r   r   r   r   r   r   warnD   s    zLog.warnc                 C   s   |  |tj dS )z&Wrapper for printing critical messagesN)r   r   r   r   r   r   r   critI   s    zLog.critc                 C   s    dt jvrdS | |tj dS )z#Wrapper for printing debug messagesr   N)osenvironr   r   r   r   r   r   r   debugN   s    
z	Log.debug) r   r   r   r   r1   getpidr(   isattyr*   r+   filenor   r   r2   gethomeZ_cache_rootZ_log_dirmkdirr-   	Exceptionclassmethodstrr   r'   r   r
   r   r.   r/   r0   r3   r   r   r   r   r      s0   r   )
r   r1   r*   enumr   pathlibr   r   r   r   r   r   r   r   <module>   s   
A