i^dZddlZddlmZGddejZGddZdS)z pySim: Logging N)stylec$eZdZfdZdZxZS)_PySimLogHandlercVt||_dSN)super__init__ log_callback)selfr __class__s 7/home/jenkins/workspace/simtester-sanitize/pySim/log.pyr z_PySimLogHandler.__init__s' (c\||}|||dSr)formatr )r recordformatted_messages r emitz_PySimLogHandler.emit"s1 KK// +V44444r)__name__ __module__ __qualname__r r __classcell__)r s@r rrsG)))))5555555rrcReZdZdZdZdezZejeZejeZ dZ iZ dZ ej ejdZedidfdedefd Zedd efd Zeejfd efd ZedZedefdZdS) PySimLoggera Static class to centralize the log output of PySim applications. This class can be used to print log messages from any pySim module. Configuration of the log behaviour (see setup and set_ methods) is entirely optional. In case no print callback is set (see setup method), the logger will pass the log messages directly to print() without applying any formatting to the original log message. z%(levelname)s: %(message)sz%(module)s.%(lineno)d -- NFc td)Nz static class, do not instantiate) RuntimeError)r s r r zPySimLogger.__init__>s=>>>rcolors verbose_debugc6|t_|t_|r@tdtt jdStdtt jdS)aC Set a print callback function and color scheme. This function call is optional. In case this method is not called, default settings apply. Args: print_callback : A callback function that accepts the resulting log string as input. The callback should have the following format: print_callback(message:str) colors : An optional dict through which certain log levels can be assigned a color. (e.g. {logging.WARN: YELLOW}) verbose_debug: Enable verbose logging and set the loglevel DEBUG when set to true. Otherwise the non-verbose logging is used and the loglevel is set to INFO. This setting can be changed using the set_verbose and set_level methods at any time. TFN)rprint_callbackr set_verbose set_levelloggingDEBUGINFO)rrrs r setupzPySimLogger.setupAs|&4 "#   0  # #D ) ) )  ! !'- 0 0 0 0 0  # #E * * *  ! !', / / / / /rverbosec|t_dS)z Enable/disable verbose logging. (has no effect in case no print callback is set, see method setup) Args: verbose: verbosity (True = verbose logging, False = normal logging) N)rr&)r&s r r zPySimLogger.set_verboseYs& rlevelcDtj|dS)z Set the logging level. Args: level: Logging level, valis log leves are: DEBUG, INFO, WARNING, ERROR and CRITICAL N)r"rootsetLevel)r(s r r!zPySimLogger.set_levelbs   e$$$$$rcPtjst|jdStjr+t jtj|}n*t jtj |}tj |j }|rbt|tr"t||zdzdStt||dSt|dS)Nz)fg)rrprintmessager&r" Formatterr_PySimLogger__formatter_verbose_PySimLogger__formatterrgetlevelno isinstancestrr)r/rrcolors r _log_callbackzPySimLogger._log_callbackks ) > &. ! ! ! ! !" ^$+$5$<$<[=\^d$e$e!!$+$5$<$<[=TV\$]$]!&**6>::E >eS))U..u7H/H9/TUUUUU..u5FU/S/S/STTTTT**+<=====r log_facilityctj|}ttj}|||S)z Set up and return a new python logger object Args: log_facility : Name of log facility (e.g. "MAIN", "RUNTIME"...) )r )r" getLoggerrrr8 addHandler)r9loggerhandlers r r3zPySimLogger.gets@"<00" 0IJJJ'""" r)F)rrr__doc__ LOG_FMTSTRLOG_FMTSTR_VERBOSEr"r0r2r1rrr&r*r+r#r staticmethoddictboolr%r intr!r8r6r3rr rr&sk.J4zA#'#J//K+'+,>??NFG L'-(((???#2E00D0T000\0.''D'''\'%m%%%%%\%>>\>( #   \   rr)r?r"cmd2rHandlerrrrFrr rIs.55555w555ddddddddddr