{"id":24941968,"url":"https://github.com/dr-montasir/styledlog","last_synced_at":"2026-02-16T07:31:45.947Z","repository":{"id":274703150,"uuid":"920858991","full_name":"dr-montasir/styledlog","owner":"dr-montasir","description":"A Rust crate combining versatile logging features with styled output.","archived":false,"fork":false,"pushed_at":"2025-01-30T01:50:14.000Z","size":7813,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-12-07T05:57:47.635Z","etag":null,"topics":["colored","level","log","styled","tabled"],"latest_commit_sha":null,"homepage":"https://crates.io/crates/styledlog","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dr-montasir.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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}},"created_at":"2025-01-22T22:25:23.000Z","updated_at":"2025-01-30T02:01:58.000Z","dependencies_parsed_at":null,"dependency_job_id":"59259aa7-a9b1-49b8-9e07-503b0d946ddc","html_url":"https://github.com/dr-montasir/styledlog","commit_stats":null,"previous_names":["dr-montasir/styledlog"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/dr-montasir/styledlog","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dr-montasir%2Fstyledlog","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dr-montasir%2Fstyledlog/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dr-montasir%2Fstyledlog/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dr-montasir%2Fstyledlog/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dr-montasir","download_url":"https://codeload.github.com/dr-montasir/styledlog/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dr-montasir%2Fstyledlog/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29502934,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-16T05:57:17.024Z","status":"ssl_error","status_checked_at":"2026-02-16T05:56:49.929Z","response_time":115,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["colored","level","log","styled","tabled"],"created_at":"2025-02-02T18:57:36.270Z","updated_at":"2026-02-16T07:31:45.942Z","avatar_url":"https://github.com/dr-montasir.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n  \u003cbr\u003e\n  \u003ca href=\"https://crates.io/crates/styledlog\"\u003e\n    \u003cimg src=\"https://github.com/dr-montasir/styledlog/raw/HEAD/logo.svg\" width=\"100\"\u003e\n  \u003c/a\u003e\n  \u003cbr\u003e\u003cbr\u003e\n  \u003cspan\u003e\n    \u003cb\u003eA Rust crate combining versatile logging features with styled output.\u003c/b\u003e\n  \u003c/span\u003e\n  \u003cbr\u003e\u003cbr\u003e\n  \u003ca href=\"https://crates.io/crates/styledlog\"\u003e\n    \u003cimg src=\"https://github.com/dr-montasir/styledlog/raw/main/styledlog.gif\" width=\"100%\" height=\"auto\"\u003e\n  \u003c/a\u003e\n  \u003cbr\u003e\u003cbr\u003e\n\n[\u003cimg alt=\"github\" src=\"https://img.shields.io/badge/github-dr%20montasir%20/%20styledlog-8da0cb?style=for-the-badge\u0026labelColor=555555\u0026logo=github\" height=\"22\"\u003e](https://github.com/dr-montasir/styledlog)[\u003cimg alt=\"crates.io\" src=\"https://img.shields.io/crates/v/styledlog.svg?style=for-the-badge\u0026color=fc8d62\u0026logo=rust\" height=\"22\"\u003e](https://crates.io/crates/styledlog)[\u003cimg alt=\"docs.rs\" src=\"https://img.shields.io/badge/docs.rs-styledlog-66c2a5?style=for-the-badge\u0026labelColor=555555\u0026logo=docs.rs\" height=\"22\"\u003e](https://docs.rs/styledlog)[\u003cimg alt=\"license\" src=\"https://img.shields.io/badge/license-apache_2.0-4a98f7.svg?style=for-the-badge\u0026labelColor=555555\u0026logo=apache\" height=\"22\"\u003e](https://choosealicense.com/licenses/apache-2.0)\n\n  \u003ch1\u003eSTYLEDLOG\u003c/h1\u003e\n  \u003cp\u003e\n    The \u003cb\u003estyledlog\u003c/b\u003e crate provides a set of utilities for logging messages with customizable styles including color, boldness, and italics, along with functionalities for styling tables and text based on user-defined templates.\n  \u003c/p\u003e\n\u003c/div\u003e\n\n## Overview\n\nThis crate allows you to format log messages with colors and styles, convert hex colors to RGBA values, and print styled tables easily. It integrates well with the `colored` crate for rich text styling in the console.\n\n## Table of Contents\n\n1. [Installation](#installation)\n2. [Usage](#usage)\n3. [Modules](#modules)\n   - [colorful](#colorful)\n   - [formatter](#formatter)\n   - [level](#level)\n4. [Examples](#examples)\n   - [Coloring Text](#coloring-text)\n   - [Creating a Table with Style](#creating-a-table-with-style)\n   - [Logging Message Levels](#logging-message-levels)\n5. [License](#license)\n6. [Contributing](#contributing)\n7. [Author](#author)\n\n## Installation\n\nRun the following Cargo command in your project directory:\n\n```shell\ncargo add styledlog\n```\n\nor add styledlog to your Cargo.toml file:\n\n```toml\n[dependencies]\nstyledlog = \"MAJOR.MINOR.PATCH\" # Replace with the latest version\n```\n\n## Usage\n\nYou can start using styledlog by including it in your main file:\n\n```rust\nuse styledlog::*;\n```\n\n## Example\n\n```rust\nlet formatted_text = style_text!(\n    \"{{here}} {{is}} \\\\\\\"the\\\" {{message1}}: This {{is}} a {{test}} {{message2}}.\",\n    here =\u003e \"Here\".to_custom_color(\"#054eee80\"),\n    is =\u003e \"is\".to_custom_color(\"#ffff21\"),\n    message1 =\u003e \"message\".blue(),\n    message2 =\u003e \"message\".green().bold().italic().underline(),\n    test =\u003e \"test\".to_custom_color(\"#e1e\")\n);\n\nprintln!(\"{}\", formatted_text);\n```\n\nTo see the full features and usage examples of `styledlog`, please visit the following link:\n\n[Full Features and Usage Examples](https://docs.rs/crate/styledlog/latest/source/examples/usage.rs)\n\n## Modules\n\n### colorful\n\nThis module provides color utilities for styling strings with colors defined in hex format, allowing for both general use and custom color definitions through the `CustomColorTrait`.\n\n### formatter\n\nThis module contains functions for formatting output, including:\n\n- `style_text!`: A _macro for_ \u003cu\u003eformatting\u003c/u\u003e strings by replacing placeholders within a template. The _macro_ allows users to inject dynamic values into a string _while_ applying color and styling to those values. It creates an easy way to format complex output without the need _for_ \u003cu\u003emanual\u003c/u\u003e string concatenation.\n\n- `hex_to_rgba(hex: \u0026str) -\u003e Result\u003c(u8, u8, u8, f32), String\u003e`: Converts a hex color string to RGBA values. It parses various hex color formats (e.g., `#RRGGBB`, `#RRGGBBAA`, `#RGB`, `#RGBA`) and handles errors gracefully.\n\n- `print_table(...)`: A utility function _for_ \u003cu\u003eprinting\u003c/u\u003e a stylized table with headers, rows, and footers. It calculates column widths dynamically based on the content and formats the table _for_ \u003cu\u003eeasy\u003c/u\u003e readability _in_ the console.\n\n### level\n\nThis module handles log levels and their styles. It contains:\n\n- `log_level(newline_before: \u0026str, level: \u0026str, style_level: Style, message: \u0026str, action: \u0026str)`: Logs a message based on the provided log level and style. The action can be \"show\" or \"hide\".\n\n- `add_level(level: \u0026'static str)`: Adds a log level to the allowed list for display.\n\n- `remove_level(level: \u0026str)`: Removes a log level from the allowed list.\n\nThe `Style` struct allows you to define new styles for logs, including color bold, italic and underline embellishments.\n\n## Examples\n\n### Coloring Text\n\nYou can change the color of your text by calling:\n\n```rust\nlet text = \"Hello, World!\".to_custom_color(\"#ff5733\");\nprintln!(\"{}\", text);\n```\n\n### Creating a Table with Style\n\nTo print a table, use print_table:\n\n```rust\nuse styledlog::*;\n\nfn main() {\n    println!(); // Adding a new line for better separation\n\n    let styledtitle = style_text!(\"{{T}}{{abl}}{{e}}\", T =\u003e \"T\".cyan().italic(), abl =\u003e \"abl\".normal(), e =\u003e \"e\\t\u003c\\t(1)\\t\u003e\".cyan()).bold().dimmed();\n\n    println!(\"{}\\n\", styledtitle);\n\n    // Define header with ColoredString\n    let header: Metadata = \u0026[\n        \"Nmae\".cyan(),\n        \"Age\".magenta(),\n        \"Favorite Color\"\n            .to_uppercase()\n            .to_custom_color(\"#4f1\")\n            .bold(),\n        \"🔥\".into(),\n    ];\n\n    // Define rows (body)\n    let users: Rows = vec![\n        vec![\n            \"Ahmed Salih\".normal(),\n            \"30\".bold(),\n            \"Blue\".blue(),\n            \"\".normal(),\n        ],\n        vec![\n            \"Taiba\".green(),\n            \"25\".normal(),\n            \"Green\".green(),\n            \"v\".normal(),\n        ],\n        vec![\"Umar\".into(), \"17\".red(), \"Red\".red(), \"\".normal()],\n    ];\n\n    // Define footer with ColoredString\n    let footer: Metadata = \u0026[\n        \"End of Table\".yellow().on_green(),\n        \"\".normal(),\n        \" \".normal(),\n        \"🔥\".normal().italic(),\n    ];\n\n    // Call the function with header and footer\n    print_table(header, \u0026users, footer, 2, \"~o~\".cyan(), None);\n\n    println!();\n\n    // Call the function without header and footer, using empty slices instead\n    print_table(\u0026[], \u0026users, \u0026[], 9, \"*\".blue(), None);\n\n    println!();\n\n    // Call the function without header and footer, using empty slices instead  (custom repeat 36)\n    print_table(\u0026[], \u0026users, \u0026[], 9, \"x\".blue(), Some(36));\n\n    println!();\n\n    // Call the function without header and footer, using empty slices instead\n    print_table(\u0026[], \u0026users, \u0026[], 9, \"\".normal(), None);\n}\n```\n\n### Logging Message Levels\n\nThis is an example of how to log message levels:\n\n```rust\nuse styledlog::*;\n\nfn main() {\n    // Add log levels that we want to show\n    add_level(\"info\");\n    add_level(\"warn\");\n    add_level(\"error\");\n    add_level(\"debug\");\n    add_level(\"error/handler\");\n    add_level(\"debug/handler\");\n\n    // Define styles for different levels\n    let info_level_style = Style::new().color(Color::Green).bold();\n    let error_level_style = Style::new().color(Color::Red).bold();\n    let warn_level_style = Style::new().color(Color::BrightYellow).bold();\n    let debug_level_style = Style::new()\n        .color(Color::Yellow)\n        .bold()\n        .italic()\n        .underline();\n\n    // Log messages\n    log_level(\n        \"\\n\",\n        \"info\",\n        info_level_style,\n        \"This is an info message\",\n        \"show\",\n    );\n    log_level(\n        \"\\n\",\n        \"warn\",\n        warn_level_style,\n        \"\\nThis is a warning message\",\n        \"show\",\n    );\n\n    let style_part_of_message =\n        style_text!(\"{{this}} {{is}} an\", this=\u003e\"This\".to_custom_color(\"#0de\"), is=\u003e\"is\".magenta());\n    log_level(\n        \"\\n\",\n        \"error\",\n        error_level_style,\n        \u0026format!(\n            \"{} {} {}\",\n            style_part_of_message,\n            \"error\".red(),\n            \"message\".on_truecolor(135, 28, 167)\n        ),\n        \"show\",\n    );\n\n    // Attempt to log a message with a level that's not displayed\n    log_level(\n        \"\\n\",\n        \"debug\",\n        debug_level_style,\n        \"This is a debug message\",\n        \"show\",\n    ); // Should not print anything\n\n    let message = format!(\n        \"{}\",\n        \"This is a custom error handler message\\n\".to_custom_color(\"#1e1707\")\n    );\n    log_level(\"\\n\", \"error/handler\", Style::new(), \u0026message, \"show\");\n\n    // Attempt to log a message with a level that's not displayed\n    log_level(\n        \"\\n\",\n        \"warn/handler\",\n        warn_level_style,\n        \"This is a custom warning handler message\\n\",\n        \"show\",\n    ); // Should not print anything\n\n    log_level(\n        \"\\n\",\n        \"debug/handler\",\n        warn_level_style,\n        \u0026format!(\n            \"{}\",\n            \"This is a custom debug handler message\\n\"\n                .truecolor(0, 255, 136)\n                .underline()\n        ),\n        \"hide\",\n    ); // action: hide =\u003e Should not print anything\n}\n```\n\n## License\n\nThis project is licensed under the MIT or Apache 2.0 License - see the LICENSE file for details.\n\n## Contributing\n\nContributions are welcome! If you have suggestions or improvements, feel free to submit an issue or a pull request.\n\n---\n\n## Author\n\n[Dr. Montasir Mirghani](https://github.com/dr-montasir)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdr-montasir%2Fstyledlog","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdr-montasir%2Fstyledlog","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdr-montasir%2Fstyledlog/lists"}