Python logging: create log if not exists or open and continue logging if it does

The logging module’s FileHandler takes care of that for you. No need for complexity.

The handler takes an optional mode parameter, to specify whether it starts writing or appending data to it.

From the docs:

class logging.FileHandler(filename, mode="a", encoding=None, delay=False)

The specified file is opened and used as the stream for logging. If
mode is not specified, 'a' is used.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)