Best Python code snippet using lisa_python
Log.py
Source: Log.py
...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() # å®ä¾åä¹ååè°ç¨...
Check out the latest blogs from LambdaTest on this topic:
Automating testing is a crucial step in the development pipeline of a software product. In an agile development environment, where there is continuous development, deployment, and maintenance of software products, automation testing ensures that the end software products delivered are error-free.
Before we discuss the Joomla testing, let us understand the fundamentals of Joomla and how this content management system allows you to create and maintain web-based applications or websites without having to write and implement complex coding requirements.
The QA testing career includes following an often long, winding road filled with fun, chaos, challenges, and complexity. Financially, the spectrum is broad and influenced by location, company type, company size, and the QA tester’s experience level. QA testing is a profitable, enjoyable, and thriving career choice.
It’s strange to hear someone declare, “This can’t be tested.” In reply, I contend that everything can be tested. However, one must be pleased with the outcome of testing, which might include failure, financial loss, or personal injury. Could anything be tested when a claim is made with this understanding?
When it comes to UI components, there are two versatile methods that we can use to build it for your website: either we can use prebuilt components from a well-known library or framework, or we can develop our UI components from scratch.
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!