Documentation 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 is the primary class in Chromologger. It manages a log file and provides three public methods for writing records — log() for general informational messages, log_e() for structured exception entries, and close() to release the file handle when you are done.
Import
Constructor
Logger instance, resolves the target log file path, and opens the file in append mode.
Name or path of the log file.
- When the default
'log.log'is used, the file is created in the same directory as the calling script, detected automatically via Python’sinspectmodule. - Any other value is resolved to an absolute path using
pathlib.Path.resolve(), so both relative paths (e.g.'./logs/app.log') and absolute paths (e.g.'/var/log/app.log') are accepted.
Instance Attributes
After construction, the following attributes are available on everyLogger instance.
The exact value passed to the constructor (e.g.
'log.log' or './logs/app.log').Absolute path of the directory that contains the script which created this
Logger, resolved via inspect.currentframe().f_back.f_code.co_filename.Fully resolved absolute path to the log file. When
log_file_name is 'log.log' this is <caller_script>/log.log; otherwise it is the result of FileManager.get_abs_path(log_file_name).The open file object returned by
FileManager.open_file(). Set to -1 if the file could not be opened (e.g. the parent directory does not exist).Methods
log(msg)
[INFO] record to the log file. msg can be any Python object — it is converted to str automatically before writing.
After writing to the file, log() also prints a colorized informational message to the console via chromolog, showing the path of the log file.
The value to log. Strings, numbers, dicts, objects — anything that can be meaningfully converted with
str() is accepted.log_e(e)
[ERROR] record with full exception context — exception type, source file, line number, and the exception message — all extracted via traceback.extract_tb(e.__traceback__).
A caught exception instance. The method reads
e.__traceback__ to locate the precise file and line where the exception was raised, then reads e.__class__.__name__ for the type name and str(e) for the message.If the exception was never actually raised (i.e. it has no traceback attached),
traceback.extract_tb() will return an empty list and indexing into it will itself raise an IndexError. In that case log_e() catches the secondary exception internally via __log() and writes it to the module’s own internal log — it will not propagate to your application code.close()
True— the file was a validTextIOWrapperand has been closed successfully.False— the file was never opened (i.e.self.fileis-1); nothing was closed.
Module-level Constants
These values are exported fromchromologger alongside Logger.
| Constant | Value |
|---|---|
chromologger.__version__ | '0.1.9' |
chromologger.__author__ | 'Tutos Rive' |
Log Format Reference
Every entry written byLogger follows one of these two formats:
Dates.now_date() which returns datetime.now() — local time with microsecond precision. See the Dates reference for details.