Because Logger() accepts any file path, you have full control over how log files are named and where they are stored. You can organize them by date so older files roll off naturally, by component so you can read subsystem logs in isolation, by environment so production and development logs never mix, or by an absolute path when you need logs outside the project directory.
By date
Generate the filename dynamically from today’s date so each day’s logs land in their own file:
After a week of operation you’ll have app_20250106.log, app_20250107.log, and so on — each independently archivable or deletable.
By component
Separate concerns into distinct files that can be inspected individually:
This makes it straightforward to hand the database.log to a database administrator without exposing unrelated application output.
By environment
Read the current environment from an environment variable and include it in the filename:
Set APP_ENV=production in your deployment environment and APP_ENV=staging on a staging server so the logs from each tier are immediately distinguishable.
Absolute paths
Use os.path.join and os.path.expanduser when you need to write logs outside the project directory — for example to a system-wide log folder:
Chromologger resolves the file path with pathlib.Path.resolve().absolute()
internally, so both relative paths (e.g. ./logs/app.log) and absolute paths
are handled correctly on all platforms — including Windows, where path
separators differ.
The parent directory of the log file must exist before you call
Logger(). Chromologger will not auto-create missing directories — it will
raise a FileNotFoundError if the directory is absent. Always call
os.makedirs(os.path.dirname(path), exist_ok=True) (or the equivalent)
before constructing the logger.