Hydra Colorlog
Hydra-colorlog is a plugin for the Hydra configuration framework that enables colored logging output for Hydra applications. It specifically integrates the 'colorlog' library into Hydra's internal (`hydra_logging`) and job-specific (`job_logging`) logging mechanisms, enhancing readability. The current version is 1.2.0, and its release cadence is tied to that of the main Hydra project, which sees several updates per year.
Warnings
- breaking When using older Hydra 1.0.x with OmegaConf 2.1, attempting to load `hydra/hydra_logging/colorlog` could result in a `MissingConfigException`. This often indicates an incompatibility between the specific minor versions of Hydra and OmegaConf.
- gotcha For `hydra-colorlog` to function, you must explicitly override `hydra/job_logging` and `hydra/hydra_logging` to `colorlog` within your Hydra configuration's `defaults` list. Without this configuration, the plugin will not be active, and you will not see colored output.
- deprecated Documentation for older Hydra versions (e.g., 1.0, 1.2) explicitly states they are 'no longer actively maintained'. While `hydra-colorlog` 1.2.0 works with Hydra 1.x, users should target newer Hydra documentation and versions for active support and features.
- gotcha Older versions of Hydra (specifically around 1.1.0/1.1.1) had a bug where enabling the `colorlog` override could inadvertently disable other logging overrides, leading to unexpected logging behavior.
Install
-
pip install hydra-colorlog
Imports
- hydra_colorlog
# hydra-colorlog is typically enabled via Hydra's configuration, not direct Python import.
- ColoredFormatter
from colorlog import ColoredFormatter
Quickstart
import hydra
from omegaconf import DictConfig
import logging
log = logging.getLogger(__name__)
@hydra.main(config_path="conf", config_name="config", version_base="1.2")
def my_app(cfg: DictConfig) -> None:
log.info("This is an info message.")
log.warning("This is a warning message.")
log.error("This is an error message.")
print(f"Config: {cfg.pretty()}")
if __name__ == "__main__":
# Create a 'conf' directory and 'config.yaml' file alongside this script.
# In config.yaml, add:
# defaults:
# - override hydra/job_logging: colorlog
# - override hydra/hydra_logging: colorlog
# Example to run: python your_script_name.py
my_app()