10 examples of 'python logger levels' in Python

Every line of 'python logger levels' 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
128def setLevel(level):
129 if level == logging.DEBUG:
130 LOGGER.setLevel(logging.DEBUG)
131 else:
132 LOGGER.setLevel(level)
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

25def set_level(self, level):
26 self.log.setLevel(level)
34def set_level(self, level):
35 assert isinstance(level, FlagConstant)
36 self._level = level
115def set_level(self, level):
116 """ Change logger level.
117
118 @param level: new level
119 @type level: str
120
121 @raise ValueError: the specified level does not exist
122 """
123 try:
124 level_no = getattr(logging, level.upper())
125 except AttributeError:
126 raise ValueError("Unknown '%s' logger level" % level)
127 else:
128 self.__logger_instance.setLevel(level_no)
18def get_logger(level=logging.INFO, quite=False, debug=False, to_file=''):
19 """
20 This function initialises a logger to stdout.
21 :return: logger
22 """
23 assert level in [logging.DEBUG, logging.INFO, logging.WARNING, logging.CRITICAL]
24 logger = logging.getLogger('main')
25 formatter = logging.Formatter('%(asctime)s - %(funcName)s - %(levelname)s - %(message)s')
26 if debug:
27 level = logging.DEBUG
28 logger.setLevel(level=level)
29 if not quite:
30 if to_file:
31 fh = logging.FileHandler(to_file)
32 fh.setLevel(level=level)
33 fh.setFormatter(formatter)
34 logger.addHandler(fh)
35 else:
36 ch = logging.StreamHandler()
37 ch.setLevel(level=level)
38 ch.setFormatter(formatter)
39 logger.addHandler(ch)
40 return logger
84def _setup_python_logger(
85 logger,
86 logger_level=logging.DEBUG,
87 handlers=None,
88 remove_existing_handlers=True
89):
90 """
91 :param logger: The flask app logger
92 :param logger_level: Level for the logger (not for specific handler).
93 :param handlers: An optional list of handlers (formatter will be
94 overridden); If None, only a StreamHandler for
95 sys.stdout will be used.
96 :param remove_existing_handlers: Determines whether to remove existing
97 handlers before adding new ones
98 :return: A logger instance.
99 :rtype: Logger
100 """
101
102 if remove_existing_handlers:
103 for handler in logger.handlers:
104 logger.removeHandler(handler)
105
106 if not handlers:
107 handler = logging.StreamHandler(sys.stdout)
108 handler.setLevel(logging.DEBUG)
109 handlers = [handler]
110
111 formatter = logging.Formatter(fmt='%(asctime)s [%(levelname)s] '
112 '[%(name)s] %(message)s',
113 datefmt='%d/%m/%Y %H:%M:%S')
114 for handler in handlers:
115 handler.setFormatter(formatter)
116 logger.addHandler(handler)
117
118 logger.setLevel(logger_level)
119 return logger
87@staticmethod
88def set_write_level(level: Optional[int]):
89 Logger.WRITE_LEVEL = level
16def get_logger(level):
17 azure_logger = logging.getLogger("azure")
18 if not azure_logger.handlers:
19 azure_logger.setLevel(level)
20 handler = logging.StreamHandler(stream=sys.stdout)
21 handler.setFormatter(logging.Formatter('%(asctime)s %(name)-12s %(levelname)-8s %(message)s'))
22 azure_logger.addHandler(handler)
23
24 uamqp_logger = logging.getLogger("uamqp")
25 if not uamqp_logger.handlers:
26 uamqp_logger.setLevel(logging.INFO)
27 uamqp_logger.addHandler(handler)
28 return azure_logger
53def get_logger(level=logging.DEBUG):
54 '''Set up logging'''
55 global logger
56 if logger is None:
57 script_path = module_path()
58 logger = logging.getLogger('PixivUtil' + PixivConstant.PIXIVUTIL_VERSION)
59 logger.setLevel(level)
60 __logHandler__ = logging.handlers.RotatingFileHandler(script_path + os.sep + PixivConstant.PIXIVUTIL_LOG_FILE,
61 maxBytes=PixivConstant.PIXIVUTIL_LOG_SIZE,
62 backupCount=PixivConstant.PIXIVUTIL_LOG_COUNT,
63 encoding="utf-8")
64 __formatter__ = logging.Formatter(PixivConstant.PIXIVUTIL_LOG_FORMAT)
65 __logHandler__.setFormatter(__formatter__)
66 logger.addHandler(__logHandler__)
67 return logger
96def setLoggerLevel(level, logger_name=None):
97 """
98 Sets the logger level.
99
100 :param level: str, a string representing the desired level
101 :param logger_name: str, a string representing desired logger name for which
102 the level should change. The default is "None" will will
103 tweak the root logger level.
104
105 """
106 logging.getLogger(logger_name).setLevel(levels.get(level, logging.ERROR))

Related snippets