diff --git a/README.md b/README.md index ad2bfa1..43b6a1d 100644 --- a/README.md +++ b/README.md @@ -6,11 +6,72 @@ [![Known Vulnerabilities](https://snyk.io/test/github/cisagov/cyhy-logging/develop/badge.svg)](https://snyk.io/test/github/cisagov/cyhy-logging) This is a Python package that provides a standard logging configuration which is -used by the Cyber Hygiene system. +used by the Cyber Hygiene (CyHy) system. -## Usage ## +The logging setup uses the +[`RichHandler`](https://rich.readthedocs.io/en/stable/logging.html) to provide +visually appealing and informative log outputs, including enhanced tracebacks +when debugging. Additionally, default filters like the +[`RedactPasswordFilter`](src/cyhy_logging/log_filters.py) are applied to all log +handlers to automatically filter and redact sensitive information. - +To ensure that all logs across different parts of the CyHy system are properly +grouped under a single root, the `CYHY_ROOT_LOGGER` constant is used. By using +this constant when configuring loggers (`CYHY_ROOT_LOGGER` as the root logger), +all log messages are consistently organized under the same logging namespace, +which simplifies log management and makes it easier to locate all related logs. +Additionally, using `CYHY_ROOT_LOGGER` allows the verbosity of CyHy logs to be +increased independently without affecting the verbosity of other packages that +use the logging system. + +## Example Usage ## + +```python +from cyhy_logging import CYHY_ROOT_LOGGER, setup_logging +import logging + +# Set up logging +logger = logging.getLogger(f"{CYHY_ROOT_LOGGER}.{__name__}") +setup_logging("DEBUG") + +# Use the logger +logger.debug("This is a debug message") +logger.info("This is an info message") +logger.warning("This is a warning message") +logger.error("This is an error message") +logger.critical("This is a critical message") + +# The logger will redact sensitive information by default +logger.info("Logging into database at https://admin:password@example.com/secret") + +# Raise an exception to demonstrate the enhanced traceback +raise Exception("This is an exception") + +# Shutdown logging +logging.shutdown() +``` + +## Example Output ## + +```console +[13:37:28] DEBUG This is a debug message :9 + INFO This is an info message :10 + WARNING This is a warning message :11 + ERROR This is an error message :12 + CRITICAL This is a critical message :13 + INFO Logging into database at :16 + https://admin:****@example.com/secret +╭───────────────────── Traceback (most recent call last) ──────────────────────╮ +│ in :18 │ +│ ╭───────────────────────────────── locals ─────────────────────────────────╮ │ +│ │ CYHY_ROOT_LOGGER = 'cyhy' │ │ +│ │ logger = │ │ +│ │ logging =