How to use the snakemake.logger function in snakemake

To help you get started, we’ve selected a few snakemake examples, based on popular ways it is used in public projects.

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

github spraakbanken / sparv-pipeline / sparv / core / log_handler.py View on Github external
self.exit(self.bar_mgr, None, None, None)

            self.finished = True

            # Remove Snakemake log file if empty (which it will be unless errors occurred)
            snakemake_log_file = logger.get_logfile()
            if snakemake_log_file is not None:
                log_file = Path(snakemake_log_file)
                if log_file.is_file() and log_file.stat().st_size == 0:
                    log_file.unlink()

            print()

            # Print user-friendly error messages
            if self.messages:
                logger.logger.error("Job execution failed with the following message{}:".format(
                    "s" if len(self.messages) > 1 else ""))
                for message in self.messages:
                    (_message_type, module_name, f_name), msg = message
                    logger.logger.error("\n[{}:{}]\n{}".format(module_name, f_name, msg))
            # Defer to Snakemake's default log handler for other errors
            elif self.real_errors:
                for error in self.real_errors:
                    logger.text_handler(error)

            if self.exit_message:
                logger.logger.info(self.exit_message)

            if self.show_summary:
                if self.messages or self.real_errors:
                    print()
                elapsed = round(time.time() - self.start_time)
github spraakbanken / sparv-pipeline / sparv / core / log_handler.py View on Github external
def stop(self):
        """Stop the progress bar and output any error messages."""
        # Make sure this is only run once
        if not self.finished:
            # Stop progress bar
            if self.bar is not None:
                self.exit(self.bar_mgr, None, None, None)

            self.finished = True

            # Remove Snakemake log file if empty (which it will be unless errors occurred)
            snakemake_log_file = logger.get_logfile()
            if snakemake_log_file is not None:
                log_file = Path(snakemake_log_file)
                if log_file.is_file() and log_file.stat().st_size == 0:
                    log_file.unlink()

            print()

            # Print user-friendly error messages
            if self.messages:
                logger.logger.error("Job execution failed with the following message{}:".format(
                    "s" if len(self.messages) > 1 else ""))
                for message in self.messages:
                    (_message_type, module_name, f_name), msg = message
                    logger.logger.error("\n[{}:{}]\n{}".format(module_name, f_name, msg))
            # Defer to Snakemake's default log handler for other errors
            elif self.real_errors:
github spraakbanken / sparv-pipeline / sparv / core / log_handler.py View on Github external
if log_file.is_file() and log_file.stat().st_size == 0:
                    log_file.unlink()

            print()

            # Print user-friendly error messages
            if self.messages:
                logger.logger.error("Job execution failed with the following message{}:".format(
                    "s" if len(self.messages) > 1 else ""))
                for message in self.messages:
                    (_message_type, module_name, f_name), msg = message
                    logger.logger.error("\n[{}:{}]\n{}".format(module_name, f_name, msg))
            # Defer to Snakemake's default log handler for other errors
            elif self.real_errors:
                for error in self.real_errors:
                    logger.text_handler(error)

            if self.exit_message:
                logger.logger.info(self.exit_message)

            if self.show_summary:
                if self.messages or self.real_errors:
                    print()
                elapsed = round(time.time() - self.start_time)
                logger.logger.info("Time elapsed: {}".format(timedelta(seconds=elapsed)))
github spraakbanken / sparv-pipeline / sparv / core / log_handler.py View on Github external
print(f"Progress: {percentage}%")

            if msg["done"] == msg["total"]:
                self.stop()

        elif level == "job_info" and self.use_progressbar:
            if msg["msg"] and self.bar is not None:
                if msg["msg"].startswith("EXIT_MESSAGE: "):
                    self.exit_message = msg["msg"][14:]
                else:
                    # Only update status message, don't advance progress
                    self.bar.text(msg["msg"])

        elif level == "info":
            if msg["msg"] == "Nothing to be done.":
                logger.text_handler(msg)

        elif level == "error" and ("exit status 123" in msg["msg"] or (
            "SystemExit" in msg["msg"] and "123" in msg["msg"]
        )):
            # Exit status 123 means a SparvErrorMessage exception
            # Find log files tied to this process
            for log_file in paths.log_dir.glob("{}.*".format(os.getpid())):
                log_info = re.match(r"[^.]+\.[^.]+\.([^.]+)\.([^.]+)\.([^.]+)", log_file.stem)
                self.messages.append((log_info.groups(), log_file.read_text()))
                log_file.unlink()

        elif level in ("warning", "error", "job_error"):
            # Save other errors and warnings for later
            self.real_errors.append(msg)

        elif level == "dag_debug" and "job" in msg: