{"id":20103154,"url":"https://github.com/dotkernel/dot-log","last_synced_at":"2025-08-21T14:04:56.706Z","repository":{"id":15727201,"uuid":"78667435","full_name":"dotkernel/dot-log","owner":"dotkernel","description":"DotKernel log component extending and customizing zend-log","archived":false,"fork":false,"pushed_at":"2025-02-24T13:16:08.000Z","size":288,"stargazers_count":5,"open_issues_count":1,"forks_count":2,"subscribers_count":2,"default_branch":"5.0","last_synced_at":"2025-04-28T14:19:48.785Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://docs.dotkernel.org/dot-log/","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/dotkernel.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-01-11T18:34:28.000Z","updated_at":"2025-02-24T10:25:07.000Z","dependencies_parsed_at":"2024-04-11T13:28:45.186Z","dependency_job_id":"0875ec70-6895-4f3f-b447-b2b3c738d18c","html_url":"https://github.com/dotkernel/dot-log","commit_stats":{"total_commits":27,"total_committers":8,"mean_commits":3.375,"dds":0.6296296296296297,"last_synced_commit":"1efd60b7b9c80983aaa829acdd2da82b22593626"},"previous_names":[],"tags_count":39,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dotkernel%2Fdot-log","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dotkernel%2Fdot-log/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dotkernel%2Fdot-log/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dotkernel%2Fdot-log/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dotkernel","download_url":"https://codeload.github.com/dotkernel/dot-log/tar.gz/refs/heads/5.0","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252648573,"owners_count":21782405,"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":[],"created_at":"2024-11-13T17:34:30.105Z","updated_at":"2025-05-06T08:31:11.161Z","avatar_url":"https://github.com/dotkernel.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# dot-log\n\nRobust, composite PSR-3 compliant logger with filtering and formatting.\n\n## Documentation\n\nDocumentation is available at: https://docs.dotkernel.org/dot-log/.\n\n## Badges\n\n![OSS Lifecycle](https://img.shields.io/osslifecycle/dotkernel/dot-log)\n![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-log/5.1.0)\n\n[![GitHub issues](https://img.shields.io/github/issues/dotkernel/dot-log)](https://github.com/dotkernel/dot-log/issues)\n[![GitHub forks](https://img.shields.io/github/forks/dotkernel/dot-log)](https://github.com/dotkernel/dot-log/network)\n[![GitHub stars](https://img.shields.io/github/stars/dotkernel/dot-log)](https://github.com/dotkernel/dot-log/stargazers)\n[![GitHub license](https://img.shields.io/github/license/dotkernel/dot-log)](https://github.com/dotkernel/dot-log/blob/5.0/LICENSE.md)\n\n[![Build Static](https://github.com/dotkernel/dot-log/actions/workflows/continuous-integration.yml/badge.svg?branch=5.0)](https://github.com/dotkernel/dot-log/actions/workflows/continuous-integration.yml)\n[![codecov](https://codecov.io/gh/dotkernel/dot-log/graph/badge.svg?token=JX19KTBRCZ)](https://codecov.io/gh/dotkernel/dot-log)\n[![PHPStan](https://github.com/dotkernel/dot-log/actions/workflows/static-analysis.yml/badge.svg?branch=5.0)](https://github.com/dotkernel/dot-log/actions/workflows/static-analysis.yml)\n\n## Adding The Config Provider\n\n* Enter config/config.php\n* If there is no entry for the config provider below, add it:\n`\\Dot\\Log\\ConfigProvider::class`\n* Make sure it is added before with the Application-Specific components, e.g.: `\\Frontend\\App\\ConfigProvider.php`, `\\Admin\\App\\ConfigProvider::class`, `MyProject\\ConfigProvider::class` , etc.\n* Open the `Dot\\Log\\ConfigProvider`\n* In the dependencies section you will see an abstract factory (`LoggerAbstractServiceFactory::class`)\n* This class responds to \"selectors\" instead of class names\n  Instead of requesting the `Dot\\Log\\Logger::class` from the container, `dot-log.my_logger` should be requested\n\n## Configuring the writer(s)\n\nLoggers must have at least one writer.\n\nA writer is an object that inherits from `Dot\\Log\\Writer\\AbstractWriter`. A writer's responsibility is to record log data to a storage backend.\n\n### Writing to a file (stream)\n\nIt is possible separate logs into multiple files using writers and filters.\nFor example *warnings.log*, *errors.log*, *all_messages.log*.\n\nThe following is the simplest example to write all log messages to `/log/dk.log`\n\n```php\nreturn [\n    'dot_log' =\u003e [\n        'loggers' =\u003e [\n            'my_logger' =\u003e [\n                'writers' =\u003e [\n                     'FileWriter' =\u003e [\n                        'name' =\u003e 'FileWriter',\n                        'level'   =\u003e \\Dot\\Log\\Logger::ALERT, // this is equal to 1\n                        'options' =\u003e [\n                            'stream' =\u003e __DIR__ . '/../../log/dk.log',\n                        ],\n                    ],\n                ],\n            ]\n        ],\n    ],\n];\n```\n\n* The `FileWriter` key is optional, otherwise the writers array would be enumerative instead of associative.\n* The writer name key is a developer-provided name for that writer, the writer name key is **mandatory**.\n\nThe writer level key is not affecting the errors that are written, it is a way to organize writers.\n\nThe writer level key is optional.\n\nTo write into a file the key stream must be present in the writer options array. This is required only if writing into streams/files.\n\n## Grouping log files by date\n\nBy default, logs will be written to the same file: `log/dk.log`.\nOptionally, you can use date format specifiers wrapped between curly braces in your FileWriter's `stream` option, automatically grouping your logs by day, week, month, year etc.\nExamples:\n\n* `log/dk-{Y}-{m}-{d}.log` will write every day to a different file (eg: `log/dk-2021-01-01.log`)\n* `log/dk-{Y}-{W}.log` will write every week to a different file (eg: `log/dk-2021-10.log`)\n\nThe full list of format specifiers is available [here](https://www.php.net/manual/en/datetime.format.php).\n\n## Filtering log messages\n\nAs per PSR-3 document.\n\nThe log levels are: emergency (0), alert (1), critical (2), error (3), warn (4), notice (5), info (6), debug (7) (in order of level/importance)\n\nThe following example has three file writers using filters:\n\n* First Example: `FileWriter` - All messages are logged in `/log/dk.log`\n* Second Example: `OnlyWarningsWriter` - Only warnings are logged in `/log/warnings.log`\n* Third Example: `WarningOrHigherWriter` - All important messages (`warnings` or more critical) are logged in `/log/important_messages.log`\n\n```php\n\u003c?php\n\nreturn [\n    'dot_log' =\u003e [\n        'loggers' =\u003e [\n            'my_logger' =\u003e [\n                'writers' =\u003e [\n                    'FileWriter' =\u003e [\n                        'name'    =\u003e 'FileWriter',\n                        'level'   =\u003e \\Dot\\Log\\Logger::ALERT,\n                        'options' =\u003e [\n                            'stream' =\u003e __DIR__ . '/../../log/dk.log',\n                            'filters' =\u003e [\n                                'allMessages' =\u003e [\n                                    'name' =\u003e 'level',\n                                    'options' =\u003e [\n                                        'operator' =\u003e '\u003e=', \n                                        'level'    =\u003e \\Dot\\Log\\Logger::EMERG,\n                                    ]\n                                ],\n                            ],\n                        ],\n                    ],\n                    // Only warnings\n                    'OnlyWarningsWriter' =\u003e [\n                        'name'  =\u003e 'stream',\n                        'level' =\u003e \\Dot\\Log\\Logger::ALERT,\n                        'options' =\u003e [\n                            'stream' =\u003e __DIR__ . '/../../log/warnings_only.log',\n                            'filters' =\u003e [\n                                'warningOnly' =\u003e [\n                                    'name' =\u003e 'level',\n                                    'options' =\u003e [\n                                        'operator' =\u003e '==',\n                                        'level'    =\u003e \\Dot\\Log\\Logger::WARN,\n                                    ],\n                                ],\n                            ],\n                        ],\n                    ],\n                    // Warnings and more important messages\n                    'WarningOrHigherWriter' =\u003e [\n                        'name' =\u003e 'stream',\n                        'level' =\u003e \\Dot\\Log\\Logger::ALERT,\n                        'options' =\u003e [\n                            'stream' =\u003e __DIR__ . '/../../log/important_messages.log',\n                            'filters' =\u003e [\n                                'importantMessages' =\u003e [\n                                    'name'    =\u003e 'level',\n                                    'options' =\u003e [\n                                        // note, the smaller the level, the more important is the message\n                                        // 0 - emergency, 1 - alert, 2- error, 3 - warn. .etc\n                                        'operator' =\u003e '\u003c=',\n                                        'level'    =\u003e \\Dot\\Log\\Logger::WARN,\n                                    ],\n                                ],\n                            ],\n                        ],\n                    ],\n                ],\n            ],\n        ],\n    ],\n];\n```\n\nAs in the writer configuration, the developer can optionally use keys for associating the filters with a name.\n\nIMPORTANT NOTE: the operator for more important messages is \u003c=, this is because the number representation is smaller for a more important message type.\n\nThe filter added on the first writer is equal to not setting a filter, but it has been added to illustrate how to explicitly allow all messages.\n\nIt was added opposite to the others just to demonstrate the other operator is also an option.\n\n## Formatting Messages\n\nWhen using `dot-log`, the logged value is not limited to a string. Arrays can be logged as well.\n\nFor a better readability, these arrays can be serialized.\n\nDot Log provides String formatting and JSON formatting.\n\nThe formatter accepts following parameters:\n\nname - the formatter class (it must implement `Dot\\Log\\Formatter\\FormatterInterface`)\noptions - options to pass to the formatter constructor if required\n\nThe following formats the message as JSON data:\n\n```php\n'formatter' =\u003e [\n    'name' =\u003e \\Dot\\Log\\Formatter\\Json::class,\n],\n```\n\n### Example with formatter\n\n* The log is used through dot-log\n* The logger name is my_logger\n* Writes to file: log/dk.log\n* Explicitly allows all the messages to be written\n* Formats the messages as JSON\n\n```php\n\u003c?php\n\n\nreturn [\n    'dot_log' =\u003e [\n        'loggers' =\u003e [\n            'my_logger' =\u003e [\n                'writers' =\u003e [\n                    'FileWriter' =\u003e [\n                        'name'    =\u003e 'FileWriter',\n                        'level'   =\u003e \\Dot\\Log\\Logger::ALERT,\n                        'options' =\u003e [\n                            'stream' =\u003e __DIR__ . '/../../log/dk.log',\n                            // explicitly log all messages\n                            'filters' =\u003e [\n                                'allMessages' =\u003e [\n                                    'name'    =\u003e 'level',\n                                    'options' =\u003e [\n                                        'operator' =\u003e '\u003e=',\n                                        'level'    =\u003e \\Dot\\Log\\Logger::EMERG,\n                                    ],\n                                ],\n                            ],\n                            'formatter' =\u003e [\n                                'name' =\u003e \\Dot\\Log\\Formatter\\Json::class,\n                            ],\n                        ],\n                    ],\n                ],\n            ],\n        ],\n    ],\n];\n```\n\n## Usage\n\nBasic usage of the logger is illustrated below.\n\nThe messages are written to see which logs are written and which are not written.\n\n```php\nuse Dot\\Log\\Logger;\n```\n\n...\n\n```php\n$logger = $container-\u003eget('dot-log.my_logger');\n\n/** @var Logger $logger */\n$logger-\u003eemergency('0 EMERG');\n$logger-\u003ealert('1 ALERT');\n$logger-\u003ecritical('2 CRITICAL');\n$logger-\u003eerror('3 ERR');\n$logger-\u003ewarning('4 WARN');\n$logger-\u003enotice('5 NOTICE');\n$logger-\u003einfo('6 INF');\n$logger-\u003edebug('7 debug');\n$logger-\u003elog(Logger::NOTICE, 'NOTICE from log()');\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdotkernel%2Fdot-log","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdotkernel%2Fdot-log","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdotkernel%2Fdot-log/lists"}