{"id":34086923,"url":"https://github.com/jpl-evapotranspiration-algorithms/colored-logging","last_synced_at":"2026-04-06T07:01:57.743Z","repository":{"id":249283686,"uuid":"823372917","full_name":"JPL-Evapotranspiration-Algorithms/colored-logging","owner":"JPL-Evapotranspiration-Algorithms","description":"formats logging messages in color","archived":false,"fork":false,"pushed_at":"2025-12-09T23:07:29.000Z","size":34,"stargazers_count":2,"open_issues_count":1,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-01-02T20:56:04.973Z","etag":null,"topics":["pip"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/JPL-Evapotranspiration-Algorithms.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-07-02T23:15:11.000Z","updated_at":"2025-12-09T23:07:04.000Z","dependencies_parsed_at":"2025-09-16T18:16:32.087Z","dependency_job_id":null,"html_url":"https://github.com/JPL-Evapotranspiration-Algorithms/colored-logging","commit_stats":null,"previous_names":["jpl-evapotranspiration-algorithms/colored_logging","jpl-evapotranspiration-algorithms/colored-logging"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/JPL-Evapotranspiration-Algorithms/colored-logging","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JPL-Evapotranspiration-Algorithms%2Fcolored-logging","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JPL-Evapotranspiration-Algorithms%2Fcolored-logging/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JPL-Evapotranspiration-Algorithms%2Fcolored-logging/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JPL-Evapotranspiration-Algorithms%2Fcolored-logging/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JPL-Evapotranspiration-Algorithms","download_url":"https://codeload.github.com/JPL-Evapotranspiration-Algorithms/colored-logging/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JPL-Evapotranspiration-Algorithms%2Fcolored-logging/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31463015,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-05T21:22:52.476Z","status":"online","status_checked_at":"2026-04-06T02:00:07.287Z","response_time":112,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["pip"],"created_at":"2025-12-14T13:34:51.083Z","updated_at":"2026-04-06T07:01:57.737Z","avatar_url":"https://github.com/JPL-Evapotranspiration-Algorithms.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# `colored-logging` Python Package\n\nA Python package for enhanced logging with automatic color-coding, semantic highlighting, and flexible configuration. This package provides consistent, visually organized logging output across console and file outputs.\n\n[Gregory H. Halverson](https://github.com/gregory-halverson-jpl) (they/them)\u003cbr\u003e\n[gregory.h.halverson@jpl.nasa.gov](mailto:gregory.h.halverson@jpl.nasa.gov)\u003cbr\u003e\nNASA Jet Propulsion Laboratory 329G\n\n## Features\n\n- 🎨 **Automatic Color Coding**: INFO, WARNING, and ERROR messages are automatically color-coded\n- 🏷️ **Semantic Highlighting**: Built-in functions to color-code files, directories, URLs, times, places, values, and names\n- 📝 **Dual Output**: Simultaneously log to console and file with different formatting rules\n- 🔧 **Configurable**: Customize log format, date format, and ANSI escape sequence handling\n- 🧹 **ANSI Stripping**: Automatically strip color codes from file output while keeping console colorized\n- 🔀 **Stream Separation**: Different log levels directed to appropriate output streams\n\n## Installation\n\nThis package is available as a [pip package](https://pypi.org/project/colored-logging/) called `colored-logging` with a dash.\n\n### Using pip\n\n```bash\npip install colored-logging\n```\n\n### Using conda\n\nOnce published to conda-forge, you can install via:\n\n```bash\nconda install -c conda-forge colored-logging\n```\n\n## Quick Start\n\nImport this package as `colored_logging` with an underscore:\n\n```python\nimport logging\nimport colored_logging as cl\n\n# Configure the logger (optional - uses defaults if not called)\ncl.configure()\n\n# Get a logger instance\nlogger = logging.getLogger(__name__)\n\n# Start logging with automatic color-coding\nlogger.info(\"Processing started\")\nlogger.warning(\"This will appear in yellow\")\nlogger.error(\"This will appear in red\")\n```\n\n## Basic Usage\n\n### Simple Logging\n\n```python\nimport logging\nimport colored_logging as cl\n\nlogger = logging.getLogger(__name__)\n\n# INFO messages appear in standard color\nlogger.info(\"Application started successfully\")\n\n# WARNING messages automatically appear in yellow\nlogger.warning(\"Configuration file not found, using defaults\")\n\n# ERROR messages automatically appear in red\nlogger.error(\"Failed to connect to database\")\n```\n\n### Semantic Color Functions\n\nUse semantic color functions to highlight different types of information:\n\n```python\nimport logging\nimport colored_logging as cl\n\nlogger = logging.getLogger(__name__)\n\n# Highlight file paths\nlogger.info(f\"Loading configuration from {cl.file('config.yaml')}\")\n\n# Highlight directories\nlogger.info(f\"Output will be saved to {cl.dir('/data/results/')}\")\n\n# Highlight URLs\nlogger.info(f\"Fetching data from {cl.URL('https://api.example.com/data')}\")\n\n# Highlight values\nlogger.info(f\"Processing {cl.val('1000')} records\")\n\n# Highlight names/keys\nlogger.info(f\"Using model: {cl.name('ResNet50')}\")\n\n# Highlight times\nlogger.info(f\"Started at {cl.time('2024-12-09 14:30:00')}\")\n\n# Highlight places\nlogger.info(f\"Server location: {cl.place('us-west-2')}\")\n```\n\n### Complex Messages\n\nCombine multiple semantic colors in a single message:\n\n```python\nimport logging\nimport colored_logging as cl\n\nlogger = logging.getLogger(__name__)\n\nlogger.info(\n    f\"Saved {cl.val('500')} records to {cl.file('output.csv')} \"\n    f\"in {cl.dir('/home/user/data/')} at {cl.time('14:25:30')}\"\n)\n\nlogger.info(\n    f\"Configuration: {cl.name('batch_size')}={cl.val('32')}, \"\n    f\"{cl.name('learning_rate')}={cl.val('0.001')}\"\n)\n\nlogger.info(\n    f\"Downloaded {cl.file('dataset.zip')} from \"\n    f\"{cl.URL('https://storage.example.com/data')} \"\n    f\"to {cl.dir('./downloads/')}\"\n)\n```\n\n## Advanced Configuration\n\n### Basic Configuration\n\nThe `configure()` function sets up the logging system with sensible defaults:\n\n```python\nimport colored_logging as cl\n\n# Use default settings\ncl.configure()\n```\n\n### Logging to a File\n\nSpecify a filename to enable file logging alongside console output:\n\n```python\nimport colored_logging as cl\n\n# Log to both console and file\ncl.configure(filename=\"application.log\")\n\n# Expand home directory in path\ncl.configure(filename=\"~/logs/app.log\")\n```\n\n### Custom Format Strings\n\nCustomize the log message format and date format:\n\n```python\nimport colored_logging as cl\n\n# Custom format with more details\ncl.configure(\n    format=\"[%(asctime)s %(name)s %(levelname)s] %(message)s\",\n    datefmt=\"%Y-%m-%d %H:%M:%S\"\n)\n\n# Simpler format\ncl.configure(\n    format=\"%(levelname)s: %(message)s\",\n    datefmt=\"%H:%M:%S\"\n)\n\n# Include module and function names\ncl.configure(\n    format=\"[%(asctime)s %(name)s:%(funcName)s %(levelname)s] %(message)s\"\n)\n```\n\n### ANSI Escape Sequence Handling\n\nControl whether ANSI color codes are stripped from console and file output:\n\n```python\nimport colored_logging as cl\n\n# Keep colors in console, strip from file (default)\ncl.configure(\n    filename=\"app.log\",\n    strip_console=False,\n    strip_file=True\n)\n\n# Strip colors from both console and file\ncl.configure(\n    filename=\"app.log\",\n    strip_console=True,\n    strip_file=True\n)\n\n# Keep colors in both (useful for logging to colorized terminals)\ncl.configure(\n    filename=\"app.log\",\n    strip_console=False,\n    strip_file=False\n)\n```\n\n### Full Configuration Example\n\n```python\nimport colored_logging as cl\n\ncl.configure(\n    filename=\"~/logs/myapp.log\",\n    format=\"[%(asctime)s %(name)s %(levelname)s] %(message)s\",\n    datefmt=\"%Y-%m-%d %H:%M:%S\",\n    strip_console=False,  # Keep colors in console\n    strip_file=True       # Remove colors from file\n)\n```\n\n## API Reference\n\n### Configuration Function\n\n#### `configure(filename=None, format=DEFAULT_FORMAT, datefmt=DEFAULT_DATE_FORMAT, strip_console=False, strip_file=True)`\n\nConfigure the logging system.\n\n**Parameters:**\n- `filename` (str, optional): Path to log file. If provided, logs to both console and file. Supports `~` expansion.\n- `format` (str): Log message format string. Default: `\"[%(asctime)s %(levelname)s] %(message)s\"`\n- `datefmt` (str): Date format string. Default: `\"%Y-%m-%d %H:%M:%S\"`\n- `strip_console` (bool): Strip ANSI codes from console output. Default: `False`\n- `strip_file` (bool): Strip ANSI codes from file output. Default: `True`\n\n### Color Functions\n\nAll color functions accept any type and convert it to a colored string.\n\n#### `file(text)` → str\nColor text as a file path (blue).\n\n#### `dir(text)` → str\nColor text as a directory path (blue).\n\n#### `URL(text)` → str\nColor text as a URL (blue).\n\n#### `time(text)` → str\nColor text as a time value (green).\n\n#### `place(text)` → str\nColor text as a place/location (yellow).\n\n#### `val(text)` → str\nColor text as a value (cyan).\n\n#### `name(text)` → str\nColor text as a name/identifier (yellow).\n\n### Utility Functions\n\n#### `strip(text)` → str\nRemove all ANSI escape sequences from text.\n\n```python\nimport colored_logging as cl\n\ncolored_text = cl.file(\"example.txt\")\nplain_text = cl.strip(colored_text)\n```\n\n## Complete Example\n\n```python\nimport logging\nimport colored_logging as cl\n\n# Configure logging\ncl.configure(\n    filename=\"~/logs/myapp.log\",\n    format=\"[%(asctime)s %(name)s %(levelname)s] %(message)s\",\n    datefmt=\"%Y-%m-%d %H:%M:%S\"\n)\n\n# Get logger\nlogger = logging.getLogger(__name__)\n\n# Application workflow with colored logging\nlogger.info(\"Application started\")\n\nconfig_file = \"config.yaml\"\nlogger.info(f\"Loading configuration from {cl.file(config_file)}\")\n\ndata_dir = \"/data/input/\"\nfile_count = 150\nlogger.info(f\"Found {cl.val(file_count)} files in {cl.dir(data_dir)}\")\n\nmodel_name = \"ResNet50\"\nbatch_size = 32\nlogger.info(\n    f\"Initializing model {cl.name(model_name)} \"\n    f\"with batch size {cl.val(batch_size)}\"\n)\n\noutput_path = \"/data/output/results.csv\"\nrecords = 1000\nlogger.info(f\"Saved {cl.val(records)} records to {cl.file(output_path)}\")\n\napi_url = \"https://api.example.com/submit\"\nlogger.info(f\"Uploading results to {cl.URL(api_url)}\")\n\n# Warning example\nif file_count \u003e 100:\n    logger.warning(f\"Large number of files ({cl.val(file_count)}) may slow processing\")\n\n# Error example\ntry:\n    # Some operation that might fail\n    raise ValueError(\"Invalid configuration\")\nexcept ValueError as e:\n    logger.error(f\"Configuration error: {e}\")\n\nlogger.info(\"Application completed successfully\")\n```\n\n## Color Scheme\n\nDefault color assignments:\n\n| Element | Color | Use Case |\n|---------|-------|----------|\n| Files | Blue | File paths, filenames |\n| Directories | Blue | Directory paths, folders |\n| URLs | Blue | Web addresses, API endpoints |\n| Times | Green | Timestamps, durations |\n| Places | Yellow | Locations, regions, zones |\n| Values | Cyan | Numbers, counts, measurements |\n| Names | Yellow | Identifiers, keys, model names |\n| INFO | Default | Standard informational messages |\n| WARNING | Yellow | Warnings and cautions |\n| ERROR | Red | Errors and critical issues |\n\n## Best Practices\n\n1. **Use semantic functions**: Apply `cl.file()`, `cl.dir()`, `cl.val()`, etc. to make logs more readable\n2. **Configure once**: Call `cl.configure()` at the start of your application\n3. **Consistent naming**: Use the standard `logger = logging.getLogger(__name__)` pattern\n4. **File logging**: Always log to a file in production for troubleshooting\n5. **Strip ANSI in files**: Keep `strip_file=True` to ensure clean log files\n6. **Descriptive messages**: Combine colored elements with clear descriptions\n\n## Requirements\n\n- Python \u003e= 3.10\n- termcolor\n\n## License\n\nApache License 2.0\n\n## Contributing\n\nIssues and pull requests are welcome at the [GitHub repository](https://github.com/JPL-Evapotranspiration-Algorithms/colored-logging).\n\n## Links\n\n- [PyPI Package](https://pypi.org/project/colored-logging/)\n- [GitHub Repository](https://github.com/JPL-Evapotranspiration-Algorithms/colored-logging)\n- [Issue Tracker](https://github.com/JPL-Evapotranspiration-Algorithms/colored-logging/issues)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjpl-evapotranspiration-algorithms%2Fcolored-logging","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjpl-evapotranspiration-algorithms%2Fcolored-logging","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjpl-evapotranspiration-algorithms%2Fcolored-logging/lists"}