Logging Configuration#
ContextGem provides comprehensive logging to help you monitor and debug the extraction process. You can control logging behavior using environment variables.
⚙️ Environment Variables#
ContextGem uses a single environment variable for logging configuration:
- CONTEXTGEM_LOGGER_LEVEL
Sets the logging level. Valid values are:
TRACE
- Most verbose, shows all log messagesDEBUG
- Shows debug information and aboveINFO
- Shows informational messages and above (default)SUCCESS
- Shows success messages and aboveWARNING
- Shows warnings and errors onlyERROR
- Shows errors and critical messages onlyCRITICAL
- Shows only critical messagesOFF
- Completely disables logging
Default:
INFO
Warning
Not recommended: Setting the level to OFF
or above INFO
(such as WARNING
or ERROR
) may cause you to miss helpful messages, guidance, recommendations, and important information about the extraction process. The default INFO
level provides a good balance of useful information without being too verbose.
🔧 Setting Environment Variables#
Before importing ContextGem:
# Set logging level to WARNING
export CONTEXTGEM_LOGGER_LEVEL=WARNING
# Disable logging completely
export CONTEXTGEM_LOGGER_LEVEL=OFF
In Python before import:
import os
# Set logging level to DEBUG
os.environ["CONTEXTGEM_LOGGER_LEVEL"] = "DEBUG"
# Import ContextGem after setting environment variables
import contextgem
🔄 Changing Settings at Runtime#
If you need to change logging settings after importing ContextGem, use the reload_logger_settings()
function:
import os
from contextgem import reload_logger_settings
# Initial logger settings are loaded from environment variables at import time
# Change logger level to WARNING
os.environ["CONTEXTGEM_LOGGER_LEVEL"] = "WARNING"
print("Setting logger level to WARNING")
reload_logger_settings()
# Now the logger will only show WARNING level and above messages
# Disable the logger completely
os.environ["CONTEXTGEM_LOGGER_LEVEL"] = "OFF"
print("Disabling the logger")
reload_logger_settings()
# Now the logger is disabled and won't show any messages
# You can re-enable the logger by setting it back to a valid level
# os.environ["CONTEXTGEM_LOGGER_LEVEL"] = "INFO"
# reload_logger_settings()
📋 Log Format#
ContextGem logs use the following format:
[contextgem] 2025-01-11 15:30:45.123 | INFO | Your log message here
Each log entry includes:
Timestamp
Log level
Log message