Following these patterns helps keep your logs useful, consistent, and your application’s resource usage clean. The recommendations below reflect theDocumentation 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 API as it exists today and apply equally whether you are building a small script or a larger multi-component application.
Always close loggers
EveryLogger holds an open file handle. If the handle is not explicitly closed, buffered writes may not be flushed to disk and the file descriptor will remain open until the process exits. Use a finally block to guarantee close() is called even when an exception occurs:
finally block runs regardless of whether run_job() succeeded or raised an exception, so the file is always released.
Use log() for events, log_e() only for exceptions
log() produces [INFO] entries. log_e() produces [ERROR] entries with structured traceback fields (Exception, File, ErrorLine, Message). Reserve log_e() for real exception objects caught in an except block:
log() to describe an error, Chromologger has no traceback to extract, so the File and ErrorLine fields are never populated. You lose the exact location of the problem.
Write informative messages
Log entries that omit context are hard to act on when something goes wrong. Include the relevant values — counts, identifiers, paths — directly in the message:grep for when you need to trace the history of a particular record or operation.
Check logger validity before use
IfLogger() fails to open the file (for example, because the directory does not exist), logger.file is set to -1 rather than a TextIOWrapper. You can guard against writing to an invalid logger by checking the type:
The following features are on the Chromologger roadmap and are not yet
available in the current release:
- Additional log levels —
WARNING,DEBUG, andCRITICALin addition toINFOandERROR - Context manager support — using
Loggerwith awithstatement for automatic cleanup - Log rotation — automatic rotation by file size or date
- Structured export — writing log entries in JSON or CSV format