Logging.

ebcc.core.logging.Logger(name, level=logging.INFO)

Bases: Logger

Logger with a custom output level.

Initialise the logger.

Source code in ebcc/core/logging.py
def __init__(self, name: str, level: int = logging.INFO) -> None:
    """Initialise the logger."""
    super().__init__(name, level)

ebcc.core.logging.Logger.output(msg, *args, **kwargs)

Output a message at the "OUTPUT" level.

Source code in ebcc/core/logging.py
def output(self, msg: str, *args: Any, **kwargs: Any) -> None:
    """Output a message at the `"OUTPUT"` level."""
    if self.isEnabledFor(25):
        self._log(25, msg, args, **kwargs)

ebcc.core.logging.NullLogger(*args, **kwargs)

Bases: Logger

A logger that does nothing.

Initialise the logger.

Source code in ebcc/core/logging.py
def __init__(self, *args: Any, **kwargs: Any) -> None:
    """Initialise the logger."""
    super().__init__("null")

ebcc.core.logging.init_logging(log)

Initialise the logging with a header.

Source code in ebcc/core/logging.py
def init_logging(log: Logger) -> None:
    """Initialise the logging with a header."""
    if globals().get("_EBCC_LOG_INITIALISED", False):
        return

    # Print header
    header_size = max([len(line) for line in HEADER.split("\n")])
    space = " " * (header_size - len(__version__))
    log.info(f"{ANSI.B}{HEADER}{ANSI.R}" % f"{space}{ANSI.B}{__version__}{ANSI.R}")

    # Print versions of dependencies and ebcc
    def get_git_hash(directory: str) -> str:
        git_directory = os.path.join(directory, ".git")
        cmd = ["git", "--git-dir=%s" % git_directory, "rev-parse", "--short", "HEAD"]
        try:
            git_hash = subprocess.check_output(
                cmd, universal_newlines=True, stderr=subprocess.STDOUT
            ).rstrip()
        except subprocess.CalledProcessError:
            git_hash = "N/A"
        return git_hash

    import numpy
    import pyscf

    log.info("numpy:")
    log.info(" > Version:  %s" % numpy.__version__)
    log.info(" > Git hash: %s" % get_git_hash(os.path.join(os.path.dirname(numpy.__file__), "..")))

    log.info("pyscf:")
    log.info(" > Version:  %s" % pyscf.__version__)
    log.info(" > Git hash: %s" % get_git_hash(os.path.join(os.path.dirname(pyscf.__file__), "..")))

    log.info("ebcc:")
    log.info(" > Version:  %s" % __version__)
    log.info(" > Git hash: %s" % get_git_hash(os.path.join(os.path.dirname(__file__), "..")))

    # Environment variables
    log.info("OMP_NUM_THREADS = %s" % os.environ.get("OMP_NUM_THREADS", ""))

    log.debug("")

    globals()["_EBCC_LOG_INITIALISED"] = True