o
    sg                  
   @   s   d Z ddlZddlZddlZddlmZ ddlZdZG dd dZe	 Z
e
d edkr]e
d	 z	e
d
 ed eyU Z ze
jddd W Y dZ[ndZ[ww e
d dS dS )zModule for Logging Errors    N)RotatingFileHandlerzconfigs/logging_config.yamlc                       s:   e Zd ZdZdZ	d fdd	Zdd	 Zdd
dZ  ZS )ServiceLoggerzPLogger class for logging messages with optional error information and traceback.Nlogs/service.log  P    c                    s.   | j d u rtt| | | _ | j t | j S N)	_instancesuperr   __new___initializeyaml_config_file)clslog_filemax_size_bytesbackup_count	__class__ (/var/www/html/XCapMarket/utils/logger.pyr
      s   
zServiceLogger.__new__c                 C   sp   t |d)}t| }|d d d }tjtj|dd tj	
| W d    d S 1 s1w   Y  d S )NrhandlersfilefilenameT)exist_ok)openyaml	safe_loadreadosmakedirspathdirnameloggingconfig
dictConfig)selfconfig_filefconfig_textlog_filenamer   r   r   r      s   "zServiceLogger._initializec                 C   s   |du rt  S t |S )zReturn the logger instance.N)r"   	getLogger)r%   namer   r   r   
get_logger$   s   
zServiceLogger.get_logger)r   r   r   r   )	__name__
__module____qualname____doc__r   r
   r   r,   __classcell__r   r   r   r   r      s    
r   zLogging system initialized.__main__zScript execution started.TESTzExample errorzAn error occurred.T)exc_infozCompleted processing.)r0   r"   logging.configr   logging.handlersr   r   r   r   r*   
XCM_loggerinfor-   
ValueErroreerrorr   r   r   r   <module>   s*    


