Mercurial > repos > shellac > guppy_basecaller
view env/lib/python3.7/site-packages/ephemeris/ephemeris_log.py @ 4:79f47841a781 draft
"planemo upload commit 2a0fe2cc28b09e101d37293e53e82f61762262ec"
author | shellac |
---|---|
date | Thu, 14 May 2020 16:47:39 -0400 |
parents | 26e78fe6e8c4 |
children |
line wrap: on
line source
import logging import tempfile class ProgressConsoleHandler(logging.StreamHandler): """ A handler class which allows the cursor to stay on one line for selected messages """ on_same_line = False def emit(self, record): try: msg = self.format(record) stream = self.stream same_line = hasattr(record, 'same_line') if self.on_same_line and not same_line: stream.write('\r\n') stream.write(msg) if same_line: stream.write('.') self.on_same_line = True else: stream.write('\r\n') self.on_same_line = False self.flush() except (KeyboardInterrupt, SystemExit): raise except Exception: self.handleError(record) def disable_external_library_logging(): # Omit (most of the) logging by external libraries logging.getLogger('bioblend').setLevel(logging.ERROR) logging.getLogger('requests').setLevel(logging.ERROR) try: logging.captureWarnings(True) # Capture HTTPS warngings from urllib3 except AttributeError: pass def setup_global_logger(name, log_file=None): formatter = logging.Formatter('%(asctime)s %(levelname)-5s - %(message)s') progress = ProgressConsoleHandler() console = logging.StreamHandler() console.setFormatter(formatter) logger = logging.getLogger(name) logger.setLevel(logging.DEBUG) logger.addHandler(progress) if not log_file: # delete = false is chosen here because it is always nice to have a log file # ready if you need to debug. Not having the "if only I had set a log file" # moment after the fact. temp = tempfile.NamedTemporaryFile(prefix="ephemeris_", delete=False) log_file = temp.name file_handler = logging.FileHandler(log_file) logger.addHandler(file_handler) logger.info("Storing log file in: {0}".format(log_file)) return logger