Skip to content

logging

zeus.utils.logging

Utilities for logging.

FileAndConsole

Like tee, but for Python prints.

Source code in zeus/utils/logging.py
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
class FileAndConsole:
    """Like tee, but for Python prints."""

    def __init__(self, filepath: Path) -> None:
        """Initialize the object."""
        self.file = open(filepath, "w")
        self.stdout = sys.stdout

    def write(self, message):
        """Write message."""
        self.file.write(message)
        self.stdout.write(message)
        self.file.flush()
        self.stdout.flush()

    def flush(self):
        """Flush both log file and stdout."""
        self.file.flush()
        self.stdout.flush()

__init__

__init__(filepath)
Source code in zeus/utils/logging.py
10
11
12
13
def __init__(self, filepath: Path) -> None:
    """Initialize the object."""
    self.file = open(filepath, "w")
    self.stdout = sys.stdout

write

write(message)

Write message.

Source code in zeus/utils/logging.py
15
16
17
18
19
20
def write(self, message):
    """Write message."""
    self.file.write(message)
    self.stdout.write(message)
    self.file.flush()
    self.stdout.flush()

flush

flush()

Flush both log file and stdout.

Source code in zeus/utils/logging.py
22
23
24
25
def flush(self):
    """Flush both log file and stdout."""
    self.file.flush()
    self.stdout.flush()