Skip to content

logger

open_log(log_file_name, clear_log_file=False)

Sets up the root logger where it writes all logging events to file, and writing events at or above 'info' to console. Events are appended to the log file. The logger will also capture uncaught exceptions.

Parameters:

Name Type Description Default
log_file_name str

The name of the file where the log will be written to.

required
clear_log_file bool

If true, the log file will be cleared before writing to it.

False

Returns:

Type Description
None

None

Source code in src/ariadne/utils/logger.py
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
def open_log(log_file_name: str, clear_log_file: bool = False) -> None:
    """
    Sets up the root logger where it writes all logging events to file, and writing events at or above 'info' to
    console. Events are appended to the log file. The logger will also capture uncaught exceptions.

    Args:
        log_file_name: The name of the file where the log will be written to.
        clear_log_file: If true, the log file will be cleared before writing to it.

    Returns:
        None
    """

    if clear_log_file:
        open(log_file_name, "w").close()
    logger = logging.getLogger()
    logger.setLevel(logging.DEBUG)
    if not len(logger.handlers):
        _add_file_handler(logger=logger, log_file_name=log_file_name)
        _add_stream_handler(logger=logger)

    sys.excepthook = _handle_exception