How to use remove_handler method in lisa

Best Python code snippet using lisa_python

Log.py

Source:Log.py Github

copy

Full Screen

...27def set_handler(levels):28 if levels == 'error':29 logger.addHandler(MyLog.err_handler) # 向此日志记录器添加指定的处理程序。30 logger.addHandler(MyLog.handler)31def remove_handler(levels):32 if levels == 'error':33 logger.removeHandler(MyLog.err_handler)34 logger.removeHandler(MyLog.handler)35def get_current_time():36 return time.strftime(MyLog.date, time.localtime(time.time()))37class MyLog:38 path = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) # 工程根目录39 log_file = path+'/Log/log.log'40 err_file = path+'/Log/err.log'41 logger.setLevel(LEVELS.get(level, logging.INFO)) # 设置此日志记录器的日志级别。等级必须是int或str。42 create_file(log_file)43 create_file(err_file)44 date = '%Y-%m-%d %H:%M:%S'45 handler = logging.FileHandler(log_file, encoding='utf-8') # 一个处理程序类,它将格式化的日志记录写入磁盘文件。46 err_handler = logging.FileHandler(err_file, encoding='utf-8')47 @staticmethod # 静态方法无需实例化;也可以实例化后调用48 def debug(log_meg):49 set_handler('debug')50 logger.debug("[DEBUG " + get_current_time() + "]" + log_meg)51 remove_handler('debug')52 @staticmethod53 def info(log_meg):54 set_handler('info')55 logger.info("[INFO " + get_current_time() + "]" + log_meg)56 remove_handler('info')57 @staticmethod58 def warning(log_meg):59 set_handler('warning')60 logger.warning("[WARNING " + get_current_time() + "]" + log_meg)61 remove_handler('warning')62 @staticmethod63 def error(log_meg):64 set_handler('error')65 logger.error("[ERROR " + get_current_time() + "]" + log_meg)66 remove_handler('error')67 @staticmethod68 def critical(log_meg):69 set_handler('critical')70 logger.error("[CRITICAL " + get_current_time() + "]" + log_meg)71 remove_handler('critical')72if __name__ == "__main__":73 MyLog.debug("This is debug message") # 未实例化调用静态方法74 MyLog.info("This is info message")75 MyLog.warning("This is warning message")76 MyLog.error("This is error")77 MyLog.critical("This is critical message")78 mylog = MyLog() # 实例化之后再调用...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run lisa automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful