How to use 'console log in python' in Python

Every line of 'console log in python' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
30def __console(self, level, message):
31 # 创建一个FileHandler,用于写到本地
32 fh = logging.FileHandler(self.logname, 'a', encoding='utf-8') # 追加模式
33 fh.setLevel(logging.DEBUG)
34 fh.setFormatter(self.formatter)
35 self.logger.addHandler(fh)
36
37 # 创建一个StreamHandler,用于输出到控制台
38 ch = logging.StreamHandler()
39 ch.setLevel(logging.DEBUG)
40 ch.setFormatter(self.formatter)
41 self.logger.addHandler(ch)
42
43 if level == 'info':
44 self.logger.info(message)
45 elif level == 'debug':
46 self.logger.debug(message)
47 elif level == 'warning':
48 self.logger.warning(message)
49 elif level == 'error':
50 self.logger.error(message)
51 # 这两行代码是为了避免日志输出重复问题
52 self.logger.removeHandler(ch)
53 self.logger.removeHandler(fh)
54 # 关闭打开的文件
55 fh.close()
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

179def console(self, msg = '', label = None):
180 """
181 Prints a message to the console and also to the logfile.
182
183 msg : str
184 Text of the message.
185 """
186
187 self.msg(msg = msg, label = label, level = self.console_level)

Related snippets