This page walks through the complete basic workflow for using Chromologger: install the package, create aDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/Dev2Forge/chromologger/llms.txt
Use this file to discover all available pages before exploring further.
Logger instance, write informational log entries, capture exceptions with full traceback detail, and close the log file to flush and release resources. By the end you will have a working script and a clear picture of what ends up in your log file.
Install Chromologger
Install the package from PyPI. The
chromolog==0.2.5 dependency is pulled in automatically.Import and create a Logger
Import the Custom path — relative or absolute:
Logger class and create an instance. You can use the zero-config default or supply an explicit path.Default — places log.log in the same directory as the calling script:If the directory in your path does not already exist, Chromologger will raise a
FileNotFoundError and log it internally. Always create the target directory with os.makedirs(..., exist_ok=True) before passing a nested path to Logger.Log an info message
Call The line written to the file looks like:
logger.log(msg) with any value. Chromologger converts it to a string, prepends an [INFO] level tag and a microsecond-precision timestamp, and appends the line to the log file.Log an exception
Wrap risky code in a The line written to the file looks like:
try/except block and pass the caught exception to logger.log_e(e). Chromologger automatically extracts the exception type, source file, line number, and message from the live traceback.Complete working script
Putting all the steps together:app.py
What’s in the log file
After running the script above,./logs/app.log contains:
In addition to writing to the log file, Chromologger prints colorized messages to your terminal via
chromolog each time log() is called. The console output includes the full path of the active log file so you always know where to find your records, even across multiple Logger instances.Next steps
Basic logging guide
Explore logging patterns, multiple Logger instances, and organizing log files by date or component.
Logger API reference
Full reference for the
Logger constructor and all public methods: log(), log_e(), and close().