{"id":18887670,"url":"https://github.com/bramus/monolog-colored-line-formatter","last_synced_at":"2025-04-12T22:37:28.744Z","repository":{"id":24733999,"uuid":"28146305","full_name":"bramus/monolog-colored-line-formatter","owner":"bramus","description":"Colored/ANSI Line Formatter for Monolog","archived":false,"fork":false,"pushed_at":"2024-05-10T09:45:13.000Z","size":226,"stargazers_count":138,"open_issues_count":5,"forks_count":19,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-04T01:58:24.817Z","etag":null,"topics":["ansi","color","logging","monolog","php"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bramus.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","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":"2014-12-17T16:51:45.000Z","updated_at":"2025-03-19T07:23:22.000Z","dependencies_parsed_at":"2024-06-18T11:23:23.861Z","dependency_job_id":null,"html_url":"https://github.com/bramus/monolog-colored-line-formatter","commit_stats":{"total_commits":72,"total_committers":10,"mean_commits":7.2,"dds":0.1527777777777778,"last_synced_commit":"1ca4f692b7d3030a59599ffc0ad102195c005aed"},"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bramus%2Fmonolog-colored-line-formatter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bramus%2Fmonolog-colored-line-formatter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bramus%2Fmonolog-colored-line-formatter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bramus%2Fmonolog-colored-line-formatter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bramus","download_url":"https://codeload.github.com/bramus/monolog-colored-line-formatter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248643008,"owners_count":21138353,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["ansi","color","logging","monolog","php"],"created_at":"2024-11-08T07:38:52.833Z","updated_at":"2025-04-12T22:37:28.723Z","avatar_url":"https://github.com/bramus.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Monolog Colored Line Formatter\n\n[![Build Status](https://github.com/bramus/monolog-colored-line-formatter/workflows/CI/badge.svg)](https://github.com/bramus/monolog-colored-line-formatter/actions) [![Source](http://img.shields.io/badge/source-bramus/monolog--colored--line--formatter-blue.svg?style=flat-square)](https://github.com/bramus/monolog-colored-line-formatter) [![Supported PHP Versions](https://img.shields.io/packagist/php-v/bramus/monolog-colored-line-formatter)](https://github.com/bramus/monolog-colored-line-formatter) [![Version](https://img.shields.io/packagist/v/bramus/monolog-colored-line-formatter.svg?style=flat-square)](https://packagist.org/packages/bramus/monolog-colored-line-formatter) [![Downloads](https://img.shields.io/packagist/dt/bramus/monolog-colored-line-formatter.svg?style=flat-square)](https://packagist.org/packages/bramus/monolog-colored-line-formatter/stats) [![License](https://img.shields.io/packagist/l/bramus/monolog-colored-line-formatter.svg?style=flat-square)](https://github.com/bramus/monolog-colored-line-formatter/blob/master/LICENSE.txt)\n\nA Formatter for Monolog with color support\nBuilt by Bramus! - [https://www.bram.us/](https://www.bram.us/)\n\n## About\n\n`bramus/monolog-colored-line-formatter` is a formatter for use with [Monolog](https://github.com/Seldaek/monolog). It augments the [Monolog LineFormatter](https://github.com/Seldaek/monolog/blob/master/src/Monolog/Formatter/LineFormatter.php) by adding color support. To achieve this `bramus/monolog-colored-line-formatter` uses ANSI Escape Sequences – [provided by `bramus/ansi-php`](https://github.com/bramus/ansi-php) – which makes it perfect for usage on text based terminals (viz. the shell).\n\n`bramus/monolog-colored-line-formatter` ships with a default color scheme, yet it can be adjusted to fit your own needs.\n\n## Prerequisites/Requirements\n\n- PHP 8.1 or greater\n- Monolog 3.0 or greater\n\n_Looking for a version compatible with Monolog 1.x? Check out the `monolog-1.x` branch then. The version of `monolog-colored-line-formatter` that is compatible with Monolog 1.x, is `monolog-colored-line-formatter` version `~2.0`_\n\n_Looking for a version compatible with Monolog 2.x? Check out the `monolog-2.x` branch then. The version of `monolog-colored-line-formatter` that is compatible with Monolog 1.x, is `monolog-colored-line-formatter` version `~3.0.0`_\n\n## Installation\n\nInstallation is possible using Composer.\n\nInstall `monolog-colored-line-formatter`, compatible with Monolog 3.x:\n\n```bash\ncomposer require bramus/monolog-colored-line-formatter ~3.1\n```\n\nInstall `monolog-colored-line-formatter`, compatible with Monolog 2.x:\n\n```bash\ncomposer require bramus/monolog-colored-line-formatter ~3.0.0\n```\n\nInstall `monolog-colored-line-formatter`, compatible with Monolog 1.x:\n\n```bash\ncomposer require bramus/monolog-colored-line-formatter ~2.0\n```\n\n## Usage\n\nCreate an instance of `\\Bramus\\Monolog\\Formatter\\ColoredLineFormatter` and set it as the formatter for the `\\Monolog\\Handler\\StreamHandler` that you use with your `\\Monolog\\Logger` instance.\n\n```php\nuse \\Monolog\\Logger;\nuse \\Monolog\\Handler\\StreamHandler;\nuse \\Bramus\\Monolog\\Formatter\\ColoredLineFormatter;\n\n$log = new Logger('DEMO');\n$handler = new StreamHandler('php://stdout', Logger::WARNING);\n$handler-\u003esetFormatter(new ColoredLineFormatter());\n$log-\u003epushHandler($handler);\n\n$log-\u003eaddError('Lorem ipsum dolor sit amet, consectetur adipiscing elit.');\n```\n\n## Color Schemes\n\n### Available Color Schemes\n\n#### Color Scheme: DefaultScheme\n\n![Monolog Colored Line Formatter](https://user-images.githubusercontent.com/11269635/28756233-c9f63abe-756a-11e7-883f-a084f35c55e7.gif)\n\n#### Color Scheme: TrafficLight\n\n![Monolog Colored Line Formatter](https://user-images.githubusercontent.com/11269635/28756238-df0a5598-756a-11e7-929a-201bef89e6a2.gif)\n\n### Activating a Color Scheme\n\nColor Schemes are defined as classes. If you do not provide any color scheme the default one will be used.\n\nTo activate a color scheme pass it as the first argument of the `ColoredLineFormatter` Constructor. All successive arguments are the ones as required by the `\\Monolog\\Formatter\\LineFormatter` class.\n\n```php\nuse \\Monolog\\Logger;\nuse \\Monolog\\Handler\\StreamHandler;\nuse \\Bramus\\Monolog\\Formatter\\ColoredLineFormatter;\nuse \\Bramus\\Monolog\\Formatter\\ColorSchemes\\TrafficLight;\n\n$log = new Logger('DEMO');\n$handler = new StreamHandler('php://stdout', Logger::WARNING);\n$handler-\u003esetFormatter(new ColoredLineFormatter(new TrafficLight()));\n$log-\u003epushHandler($handler);\n```\n\nAlternatively it's also possible to activate it using the `setColorScheme()` method of a `ColoredLineFormatter` instance.\n\n### Creating your own Custom Color Scheme\n\nTo define your own color scheme make a class that implements the `\\Bramus\\Monolog\\Formatter\\ColorSchemes\\ColorSchemeInterface` interface. To make things more easy a trait `ColorSchemeTrait` is defined.\n\n```php\nnamespace Bramus\\Monolog\\Formatter\\ColorSchemes;\n\nuse Monolog\\Logger;\nuse Monolog\\Level;\nuse Bramus\\Ansi\\Ansi;\nuse Bramus\\Ansi\\ControlSequences\\EscapeSequences\\Enums\\SGR;\n\nclass TrafficLight implements ColorSchemeInterface\n{\n    /**\n     * Use the ColorSchemeTrait and alias its constructor\n     */\n    use ColorSchemeTrait {\n        ColorSchemeTrait::__construct as private __constructTrait;\n    }\n\n    /**\n     * [__construct description]\n     */\n    public function __construct()\n    {\n        // Call Trait Constructor, so that we have $this-\u003eansi available\n        $this-\u003e__constructTrait();\n\n        // Our Color Scheme\n        $this-\u003esetColorizeArray(array(\n            Level::Debug-\u003evalue =\u003e $this-\u003eansi-\u003ecolor([SGR::COLOR_FG_WHITE])-\u003eget(),\n            Level::Info-\u003evalue =\u003e $this-\u003eansi-\u003ecolor([SGR::COLOR_FG_GREEN])-\u003eget(),\n            Level::Notice-\u003evalue =\u003e $this-\u003eansi-\u003ecolor([SGR::COLOR_FG_CYAN])-\u003eget(),\n            Level::Warning-\u003evalue =\u003e $this-\u003eansi-\u003ecolor([SGR::COLOR_FG_YELLOW])-\u003eget(),\n            Level::Error-\u003evalue =\u003e $this-\u003eansi-\u003ecolor([SGR::COLOR_FG_RED])-\u003eget(),\n            Level::Critical-\u003evalue =\u003e $this-\u003eansi-\u003ecolor([SGR::COLOR_FG_RED])-\u003eunderline()-\u003eget(),\n            Level::Alert-\u003evalue =\u003e $this-\u003eansi-\u003ecolor([SGR::COLOR_FG_WHITE, SGR::COLOR_BG_RED_BRIGHT])-\u003eget(),\n            Level::Emergency-\u003evalue =\u003e $this-\u003eansi-\u003ecolor([SGR::COLOR_BG_RED_BRIGHT])-\u003eblink()-\u003ecolor([SGR::COLOR_FG_WHITE])-\u003eget(),\n        ));\n    }\n}\n```\n\nPlease refer to [the `bramus/ansi-php` documentation](https://github.com/bramus/ansi-php) to define your own styles and colors.\n\n## Unit Testing\n\n`bramus/monolog-colored-line-formatter` ships with unit tests using [PHPUnit](https://github.com/sebastianbergmann/phpunit/).\n\n- If PHPUnit is installed globally run `phpunit` to run the tests.\n\n- If PHPUnit is not installed globally, install it locally through composer by running `composer install --dev`. Run the tests themselves by calling `vendor/bin/phpunit`.\n\nUnit tests are also automatically run [on GitHub Actions](https://github.com/bramus/monolog-colored-line-formatter/actions?query=workflow%3ACI)\n\n## License\n\n`bramus/monolog-colored-line-formatter` is released under the MIT public license. See the enclosed `LICENSE.txt` for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbramus%2Fmonolog-colored-line-formatter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbramus%2Fmonolog-colored-line-formatter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbramus%2Fmonolog-colored-line-formatter/lists"}