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)))))5555555rrcLeZdZdZdZdezZejeZejeZ dZ iZ dZ ej ejdZedifdefdZedd efd Zeejfd efd Zed ZedefdZdS) 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 -- %(name)s - NFc td)Nz static class, do not instantiate) RuntimeError)r s r r zPySimLogger.__init__>s=>>>rcolorsc6|t_|t_dS)a 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}) N)rprint_callbackr)rrs r setupzPySimLogger.setupAs&4 "# 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 set_verbosezPySimLogger.set_verboseOs& rlevelcDtj|dS)z Set the logging level. Args: level: Logging level, valis log leves are: DEBUG, INFO, WARNING, ERROR and CRITICAL N)loggingrootsetLevel)r#s r set_levelzPySimLogger.set_levelXs   e$$$$$rctjst|jdStjr+t jtj|}n*t jtj |}tj |j }|r+tt||dSt|dS)N)fg)rrprintmessager r% Formatterr_PySimLogger__formatter_verbose_PySimLogger__formatterrgetlevelnor)r,rrcolors r _log_callbackzPySimLogger._log_callbackas) > &. ! ! ! ! !" ^$+$5$<$<[=\^d$e$e!!$+$5$<$<[=TV\$]$]!&**6>::E >**51B+O+O+OPPPPP**+<=====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% getLoggerrrr3 addHandler)r4loggerhandlers r r0zPySimLogger.getss@"<00" 0IJJJ'""" r)F)rrr__doc__ LOG_FMTSTRLOG_FMTSTR_VERBOSEr%r-r/r.rrr r&r'DEBUGr staticmethoddictrboolr"intr(r3strr0rr rr&sb.J?*L#'#J//K+'+,>??NFG L'-(((???#2 $ $D $ $ $\ $''D'''\'%m%%%%%\%>>\>" #   \   rr)r:r%cmd2rHandlerrrrCrr rFs.55555w555WWWWWWWWWWr