Python logging.trace() Examples
The following are 7
code examples of logging.trace().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
logging
, or try the search function
.
Example #1
Source File: worker.py From brozzler with Apache License 2.0 | 6 votes |
def _service_heartbeat(self): if hasattr(self, "status_info"): status_info = self.status_info else: status_info = { "role": "brozzler-worker", "ttl": self.HEARTBEAT_INTERVAL * 3, } status_info["load"] = 1.0 * self._browser_pool.num_in_use() / self._browser_pool.size status_info["browser_pool_size"] = self._browser_pool.size status_info["browsers_in_use"] = self._browser_pool.num_in_use() try: self.status_info = self._service_registry.heartbeat(status_info) self.logger.trace( "status in service registry: %s", self.status_info) except r.ReqlError as e: self.logger.error( "failed to send heartbeat and update service registry " "with info %s: %s", status_info, e)
Example #2
Source File: pykms_Misc.py From py-kms with The Unlicense | 5 votes |
def add_logging_level(levelName, levelNum, methodName = None): """ Adds a new logging level to the `logging` module and the currently configured logging class. `levelName` becomes an attribute of the `logging` module with the value `levelNum`. `methodName` becomes a convenience method for both `logging` itself and the class returned by `logging.getLoggerClass()` (usually just `logging.Logger`). If `methodName` is not specified, `levelName.lower()` is used. To avoid accidental clobberings of existing attributes, this method will raise an `AttributeError` if the level name is already an attribute of the `logging` module or if the method name is already present . Example ------- >>> add_logging_level('TRACE', logging.DEBUG - 5) >>> logging.getLogger(__name__).setLevel("TRACE") >>> logging.getLogger(__name__).trace('that worked') >>> logging.trace('so did this') >>> logging.TRACE 5 """ if not methodName: methodName = levelName.lower() if hasattr(logging, levelName) or hasattr(logging, methodName) or hasattr(logging.getLoggerClass(), methodName): return def logForLevel(self, message, *args, **kwargs): if self.isEnabledFor(levelNum): self._log(levelNum, message, args, **kwargs) def logToRoot(message, *args, **kwargs): logging.log(levelNum, message, *args, **kwargs) logging.addLevelName(levelNum, levelName) setattr(logging, levelName, levelNum) setattr(logging.getLoggerClass(), methodName, logForLevel) setattr(logging, methodName, logToRoot)
Example #3
Source File: utils.py From IDArling with GNU General Public License v3.0 | 5 votes |
def start_logging(log_path, log_name, level): """ Setup the logger: add a new log level, create a logger which logs into the console and also into a log files located at: logs/idarling.%pid%.log. """ if log_name in _loggers: return _loggers[log_name] # Add a new log level called TRACE, and more verbose that DEBUG. logging.TRACE = 5 logging.addLevelName(logging.TRACE, "TRACE") logging.Logger.trace = lambda inst, msg, *args, **kwargs: inst.log( logging.TRACE, msg, *args, **kwargs ) logging.trace = lambda msg, *args, **kwargs: logging.log( logging.TRACE, msg, *args, **kwargs ) logger = logging.getLogger(log_name) if not isinstance(level, int): level = getattr(logging, level) logger.setLevel(level) # Log to the console with a first format stream_handler = logging.StreamHandler() log_format = "[%(levelname)s] %(message)s" formatter = logging.Formatter(fmt=log_format) stream_handler.setFormatter(formatter) logger.addHandler(stream_handler) # Log to the disk with a second format file_handler = logging.FileHandler(log_path) log_format = "[%(asctime)s][%(levelname)s] %(message)s" formatter = logging.Formatter(fmt=log_format, datefmt="%H:%M:%S") file_handler.setFormatter(formatter) logger.addHandler(file_handler) _loggers[log_name] = logger return logger
Example #4
Source File: log.py From BiblioPixel with MIT License | 4 votes |
def _addLoggingLevel(levelName, levelNum, methodName=None): """ Comprehensively adds a new logging level to the `logging` module and the currently configured logging class. `levelName` becomes an attribute of the `logging` module with the value `levelNum`. `methodName` becomes a convenience method for both `logging` itself and the class returned by `logging.getLoggerClass()` (usually just `logging.Logger`). If `methodName` is not specified, `levelName.lower()` is used. To avoid accidental clobberings of existing attributes, this method will raise an `AttributeError` if the level name is already an attribute of the `logging` module or if the method name is already present Example ------- >>> addLoggingLevel('TRACE', logging.DEBUG - 5) >>> logging.getLogger(__name__).setLevel("TRACE") >>> logging.getLogger(__name__).trace('that worked') >>> logging.trace('so did this') >>> logging.TRACE 5 """ if not methodName: methodName = levelName.lower() if hasattr(logging, levelName): raise AttributeError( '{} already defined in logging module'.format(levelName)) if hasattr(logging, methodName): raise AttributeError( '{} already defined in logging module'.format(methodName)) if hasattr(logging.getLoggerClass(), methodName): raise AttributeError( '{} already defined in logger class'.format(methodName)) # This method was inspired by the answers to Stack Overflow post # http://stackoverflow.com/q/2183233/2988730, especially # http://stackoverflow.com/a/13638084/2988730 def logForLevel(self, message, *args, **kwargs): if self.isEnabledFor(levelNum): self._log(levelNum, message, args, **kwargs) def logToRoot(message, *args, **kwargs): logging.log(levelNum, message, *args, **kwargs) logging.addLevelName(levelNum, levelName) setattr(logging, levelName, levelNum) setattr(logging.getLoggerClass(), methodName, logForLevel) setattr(logging, methodName, logToRoot)
Example #5
Source File: log.py From RAFCON with Eclipse Public License 1.0 | 4 votes |
def add_logging_level(level_name, level_num, method_name=None): """Add new logging level Comprehensively adds a new logging level to the `logging` module and the currently configured logging class. `method_name` becomes a convenience method for both `logging` itself and the class returned by `logging.getLoggerClass()` (usually just `logging.Logger`). If `method_name` is not specified, `level_name.lower()` is used. :param str level_name: the level name :param int level_num: the level number/value :raises AttributeError: if the level name is already an attribute of the `logging` module or if the method name is already present Example ------- >>> add_logging_level('TRACE', logging.DEBUG - 5) >>> logging.getLogger(__name__).setLevel("TRACE") >>> logging.getLogger(__name__).trace('that worked') >>> logging.trace('so did this') >>> logging.TRACE 5 """ if not method_name: method_name = level_name.lower() if hasattr(logging, level_name): raise AttributeError('{} already defined in logging module'.format(level_name)) if hasattr(logging, method_name): raise AttributeError('{} already defined in logging module'.format(method_name)) if hasattr(logging.getLoggerClass(), method_name): raise AttributeError('{} already defined in logger class'.format(method_name)) # This method was inspired by the answers to Stack Overflow post # http://stackoverflow.com/q/2183233/2988730, especially # http://stackoverflow.com/a/13638084/2988730 def log_for_level(self, message, *args, **kwargs): if self.isEnabledFor(level_num): self._log(level_num, message, args, **kwargs) def log_to_root(message, *args, **kwargs): logging.log(level_num, message, *args, **kwargs) logging.addLevelName(level_num, level_name) setattr(logging, level_name, level_num) setattr(logging.getLoggerClass(), method_name, log_for_level) setattr(logging, method_name, log_to_root)
Example #6
Source File: worker.py From brozzler with Apache License 2.0 | 4 votes |
def run(self): self.logger.notice( 'brozzler %s - brozzler-worker starting', brozzler.__version__) last_nothing_to_claim = 0 try: while not self._shutdown.is_set(): self._service_heartbeat_if_due() if time.time() - last_nothing_to_claim > 20: try: self._start_browsing_some_sites() except brozzler.browser.NoBrowsersAvailable: logging.trace( "all %s browsers are in use", self._max_browsers) except brozzler.NothingToClaim: last_nothing_to_claim = time.time() logging.trace( "nothing to claim, all available active sites " "are already claimed by a brozzler worker") time.sleep(0.5) self.logger.notice("shutdown requested") except r.ReqlError as e: self.logger.error( "caught rethinkdb exception, will try to proceed", exc_info=True) except brozzler.ShutdownRequested: self.logger.info("shutdown requested") except: self.logger.critical( "thread exiting due to unexpected exception", exc_info=True) finally: if self._service_registry and hasattr(self, "status_info"): try: self._service_registry.unregister(self.status_info["id"]) except: self.logger.error( "failed to unregister from service registry", exc_info=True) self.logger.info( 'shutting down %s brozzling threads', len(self._browsing_threads)) with self._browsing_threads_lock: for th in self._browsing_threads: if th.is_alive(): brozzler.thread_raise(th, brozzler.ShutdownRequested) self._browser_pool.shutdown_now() # copy to avoid "RuntimeError: Set changed size during iteration" thredz = set(self._browsing_threads) for th in thredz: th.join()
Example #7
Source File: LoggerTool.py From PyFlow with Apache License 2.0 | 4 votes |
def addLoggingLevel(levelName, levelNum, methodName=None): """ Comprehensively adds a new logging level to the `logging` module and the currently configured logging class. `levelName` becomes an attribute of the `logging` module with the value `levelNum`. `methodName` becomes a convenience method for both `logging` itself and the class returned by `logging.getLoggerClass()` (usually just `logging.Logger`). If `methodName` is not specified, `levelName.lower()` is used. To avoid accidental clobberings of existing attributes, this method will raise an `AttributeError` if the level name is already an attribute of the `logging` module or if the method name is already present Example ------- >>> addLoggingLevel('TRACE', logging.DEBUG - 5) >>> logging.getLogger(__name__).setLevel("TRACE") >>> logging.getLogger(__name__).trace('that worked') >>> logging.trace('so did this') >>> logging.TRACE 5 """ if not methodName: methodName = levelName.lower() if hasattr(logging, levelName): raise AttributeError('{} already defined in logging module'.format(levelName)) if hasattr(logging, methodName): raise AttributeError('{} already defined in logging module'.format(methodName)) if hasattr(logging.getLoggerClass(), methodName): raise AttributeError('{} already defined in logger class'.format(methodName)) # This method was inspired by the answers to Stack Overflow post # http://stackoverflow.com/q/2183233/2988730, especially # http://stackoverflow.com/a/13638084/2988730 def logForLevel(self, message, *args, **kwargs): if self.isEnabledFor(levelNum): self._log(levelNum, message, args, **kwargs) def logToRoot(message, *args, **kwargs): logging.log(levelNum, message, *args, **kwargs) logging.addLevelName(levelNum, levelName) setattr(logging, levelName, levelNum) setattr(logging.getLoggerClass(), methodName, logForLevel) setattr(logging, methodName, logToRoot)