How to use remove_handler method in keyboard

Best Python code snippet using keyboard

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

Blogs

Check out the latest blogs from LambdaTest on this topic:

How To Choose The Best JavaScript Unit Testing Frameworks

JavaScript is one of the most widely used programming languages. This popularity invites a lot of JavaScript development and testing frameworks to ease the process of working with it. As a result, numerous JavaScript testing frameworks can be used to perform unit testing.

Cross Browser Testing Strategy Explained in Three Easy Steps

When you hear the term Cross Browser Testing what comes immediately to your mind? Something that decodes the literal meaning i.e. testing for cross-browsers or you can say testing an application across various browsers.

How to Perform Internationalization And Localization Testing: A Complete Guide

Nowadays, many organizations have software products (websites or apps) that are built for a global audience. One of the trickiest parts is delivering an experience that appeals to the local audience of the target market. Catering to the needs of the local users would require localization. You would have come across internationalization and localization testing when designing for the ‘global and local’ market. There is a difference between internationalization and localization testing since the tests are developed from a different market point of view.

New iPhones With iOS12 And Mozilla Firefox Goes Live For Mobile Operating System

Just earlier this month, Apple officially announced the release of a new range of iPhone flagship models for 2018. The new models named iPhone XS, iPhone XS Max, and iPhone XR comes equipped with a lot of new features, trademark notch, and new headaches for developers. To help developers out, today we brought these new devices on LambdaTest’s cross-browser compatibility testing platform, along with the latest iOS 12 version. In addition, we also bring Mozilla Firefox browsers on the latest Android and iOS devices.

Pair testing strategy in an Agile environment

Pair testing can help you complete your testing tasks faster and with higher quality. But who can do pair testing, and when should it be done? And what form of pair testing is best for your circumstance? Check out this blog for more information on how to conduct pair testing to optimize its benefits.

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 keyboard 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