{"id":21467421,"url":"https://github.com/elusivecodes/fyrelog","last_synced_at":"2025-10-25T05:03:25.337Z","repository":{"id":62508426,"uuid":"421781213","full_name":"elusivecodes/FyreLog","owner":"elusivecodes","description":"FyreLog is a free, open-source logging library for PHP.","archived":false,"fork":false,"pushed_at":"2024-11-10T01:16:18.000Z","size":168,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-11-10T02:20:17.404Z","etag":null,"topics":["log","logging","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/elusivecodes.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}},"created_at":"2021-10-27T10:57:10.000Z","updated_at":"2024-11-10T01:16:02.000Z","dependencies_parsed_at":"2024-04-30T07:45:35.792Z","dependency_job_id":"61cf1388-fa82-477c-98fa-2bd0e2616306","html_url":"https://github.com/elusivecodes/FyreLog","commit_stats":null,"previous_names":[],"tags_count":37,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elusivecodes%2FFyreLog","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elusivecodes%2FFyreLog/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elusivecodes%2FFyreLog/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elusivecodes%2FFyreLog/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/elusivecodes","download_url":"https://codeload.github.com/elusivecodes/FyreLog/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226017472,"owners_count":17560519,"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":["log","logging","php"],"created_at":"2024-11-23T08:17:57.571Z","updated_at":"2025-10-25T05:03:20.304Z","avatar_url":"https://github.com/elusivecodes.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# FyreLog\r\n\r\n**FyreLog** is a free, open-source logging library for *PHP*.\r\n\r\n\r\n## Table Of Contents\r\n- [Installation](#installation)\r\n- [Basic Usage](#basic-usage)\r\n- [Methods](#methods)\r\n- [Loggers](#loggers)\r\n    - [Array](#array)\r\n    - [File](#file)\r\n- [Logging](#logging)\r\n\r\n\r\n\r\n## Installation\r\n\r\n**Using Composer**\r\n\r\n```\r\ncomposer require fyre/log\r\n```\r\n\r\nIn PHP:\r\n\r\n```php\r\nuse Fyre\\Log\\LogManager;\r\n```\r\n\r\n\r\n## Basic Usage\r\n\r\n- `$container` is a [*Container*](https://github.com/elusivecodes/FyreContainer).\r\n- `$config` is a [*Config*](https://github.com/elusivecodes/FyreConfig).\r\n\r\n```php\r\n$logManager = new LogManager($container);\r\n```\r\n\r\nDefault configuration options will be resolved from the \"*Log*\" key in the [*Config*](https://github.com/elusivecodes/FyreConfig).\r\n\r\n**Autoloading**\r\n\r\nIt is recommended to bind the *LogManager* to the [*Container*](https://github.com/elusivecodes/FyreContainer) as a singleton.\r\n\r\n```php\r\n$container-\u003esingleton(LogManager::class);\r\n```\r\n\r\nAny dependencies will be injected automatically when loading from the [*Container*](https://github.com/elusivecodes/FyreContainer).\r\n\r\n```php\r\n$logManager = $container-\u003euse(LogManager::class);\r\n```\r\n\r\n\r\n## Methods\r\n\r\n**Build**\r\n\r\nBuild a [*Logger*](#loggers).\r\n\r\n- `$config` is an array containing configuration options.\r\n\r\n```php\r\n$logger = $logManager-\u003ebuild($config);\r\n```\r\n\r\n[*Logger*](#loggers) dependencies will be resolved automatically from the [*Container*](https://github.com/elusivecodes/FyreContainer).\r\n\r\n**Clear**\r\n\r\nClear instances and configs.\r\n\r\n```php\r\n$logManager-\u003eclear();\r\n```\r\n\r\n**Get Config**\r\n\r\nGet a [*Logger*](#loggers) config.\r\n\r\n- `$key` is a string representing the [*Logger*](#loggers) key.\r\n\r\n```php\r\n$config = $logManager-\u003egetConfig($key);\r\n```\r\n\r\nAlternatively, if the `$key` argument is omitted an array containing all configurations will be returned.\r\n\r\n```php\r\n$config = $logManager-\u003egetConfig();\r\n```\r\n\r\n**Handle**\r\n\r\n- `$level` is a string representing the log level .\r\n- `$message` is a string representing the log message.\r\n- `$data` is an array containing data to insert into the message string.\r\n- `$scope` is a string or array representing the log scope, and will default to *null*.\r\n\r\n```php\r\n$logManager-\u003ehandle($level, $message, $data, $scope);\r\n```\r\n\r\nThe supported log levels include: \"*emergency*\", \"*alert*\", \"*critical*\", \"*error*\", \"*warning*\", \"*notice*\", \"*info*\" and \"*debug*\".\r\n\r\n**Has Config**\r\n\r\nDetermine whether a [*Logger*](#loggers) config exists.\r\n\r\n- `$key` is a string representing the [*Logger*](#loggers) key, and will default to `LogManager::DEFAULT`.\r\n\r\n```php\r\n$hasConfig = $logManager-\u003ehasConfig($key);\r\n```\r\n\r\n**Is Loaded**\r\n\r\nDetermine whether a [*Logger*](#loggers) instance is loaded.\r\n\r\n- `$key` is a string representing the [*Logger*](#loggers) key, and will default to `LogManager::DEFAULT`.\r\n\r\n```php\r\n$isLoaded = $logManager-\u003eisLoaded($key);\r\n```\r\n\r\n**Set Config**\r\n\r\nSet the [*Logger*](#loggers) config.\r\n\r\n- `$key` is a string representing the [*Logger*](#loggers) key.\r\n- `$options` is an array containing configuration options.\r\n\r\n```php\r\n$logManager-\u003esetConfig($key, $options);\r\n```\r\n\r\n**Unload**\r\n\r\nUnload a [*Logger*](#loggers).\r\n\r\n- `$key` is a string representing the [*Logger*](#loggers) key, and will default to `LogManager::DEFAULT`.\r\n\r\n```php\r\n$logManager-\u003eunload($key);\r\n```\r\n\r\n**Use**\r\n\r\nLoad a shared [*Logger*](#loggers) instance.\r\n\r\n- `$key` is a string representing the [*Logger*](#loggers) key, and will default to `LogManager::DEFAULT`.\r\n\r\n```php\r\n$logger = $logManager-\u003euse($key);\r\n```\r\n\r\n[*Logger*](#loggers) dependencies will be resolved automatically from the [*Container*](https://github.com/elusivecodes/FyreContainer).\r\n\r\n\r\n## Loggers\r\n\r\nYou can load a specific logger by specifying the `className` option of the `$config` variable above.\r\n\r\nCustom loggers can be created by extending `\\Fyre\\Log\\Logger`, ensuring all below methods are implemented.\r\n\r\n**Can Handle**\r\n\r\nDetermine whether a log level can be handled.\r\n\r\n- `$level` is a string representing the log level.\r\n- `$scope` is a string or array representing the log scope, and will default to *null*.\r\n\r\n```php\r\n$canHandle = $logger-\u003ecanHandle($level, $scope);\r\n```\r\n\r\nThis method will return *true* if the `$level` is contained in the `levels` of the *Logger* config (or `levels` is set to *null*), and the `$scope` is contained in `scopes` (or `$scope` is *null* and `scopes` is an empty array, or `scopes` is set to *null*).\r\n\r\n**Handle**\r\n\r\nHandle a message log.\r\n\r\n- `$level` is a string representing the log level.\r\n- `$message` is a string representing the log message.\r\n- `$data` is an array containing data to insert into the message string.\r\n\r\n```php\r\n$logger-\u003ehandle($level, $message, $data);\r\n```\r\n\r\n\r\n## Array\r\n\r\nThe Array logger can be loaded using custom configuration.\r\n\r\n- `$options` is an array containing configuration options.\r\n    - `className` must be set to `\\Fyre\\Log\\Handlers\\ArrayLogger`.\r\n    - `levels` is an array containing the levels that should be handled, and will default to *null*.\r\n    - `scopes` is an array containing the scopes that should be handled, and will default to *[]*.\r\n\r\n```php\r\n$container-\u003euse(Config::class)-\u003eset('Log.array', $options);\r\n```\r\n\r\n**Clear**\r\n\r\nClear the log content.\r\n\r\n```php\r\n$logger-\u003eclear();\r\n```\r\n\r\n**Read**\r\n\r\nRead the log content.\r\n\r\n```php\r\n$content = $logger-\u003eread();\r\n```\r\n\r\n\r\n### File\r\n\r\nThe File logger can be loaded using custom configuration.\r\n\r\n- `$options` is an array containing configuration options.\r\n    - `className` must be set to `\\Fyre\\Log\\Handlers\\FileLogger`.\r\n    - `dateFormat` is a string representing the date format, and will default to \"*Y-m-d H:i:s*\".\r\n    - `levels` is an array containing the levels that should be handled, and will default to *null*.\r\n    - `scopes` is an array containing the scopes that should be handled, and will default to *[]*.\r\n    - `path` is a string representing the directory path, and will default to \"*/var/log*\".\r\n    - `file` is a string representing the file name, and will default *null* (the type of log will be used instead).\r\n    - `suffix` is a string representing the filename suffix, and will default to *null* (or \"*-cli*\" if running from the CLI).\r\n    - `extension` is a string representing the file extension, and will default to \"*log*\".\r\n    - `maxSize` is a number representing the maximum file size before log rotation, and will default to *1048576*.\r\n\r\n```php\r\n$container-\u003euse(Config::class)-\u003eset('Log.file', $options);\r\n```\r\n\r\n\r\n## Logging\r\n\r\nGenerally, logging is done by calling the `handle` method of a *LogManager* instance.\r\n\r\nThis will call the `canHandle` method of all defined logger configs, and if that returns *true* then the `handle` method will also be called.\r\n\r\nThe default log levels are shown below (in order of severity).\r\n\r\n- `$message` is a string representing the log message.\r\n- `$data` is an array containing data to insert into the message string.\r\n- `$scope` is a string or array representing the log scope, and will default to *null*.\r\n\r\n```php\r\n$logManager-\u003ehandle('emergency', $message, $data, $scope);\r\n$logManager-\u003ehandle('alert', $message, $data, $scope);\r\n$logManager-\u003ehandle('critical', $message, $data, $scope);\r\n$logManager-\u003ehandle('error', $message, $data, $scope);\r\n$logManager-\u003ehandle('warning', $message, $data, $scope);\r\n$logManager-\u003ehandle('notice', $message, $data, $scope);\r\n$logManager-\u003ehandle('info', $message, $data, $scope);\r\n$logManager-\u003ehandle('debug', $message, $data, $scope);\r\n```\r\n\r\nThere are default placeholders that can also be used in log messages:\r\n\r\n- *{post_vars}* will be replaced with the `$_POST` data.\r\n- *{get_vars}* will be replaced with the `$_GET` data.\r\n- *{server_vars}* will be replaced with the `$_SERVER` data.\r\n- *{session_vars}* will be replaced with the `$_SESSION` data.\r\n- *{backtrace}* will be replaced with the backtrace.\r\n\r\nSee the [*MessageFormatter::formatMessage*](https://www.php.net/manual/en/messageformatter.formatmessage.php) method for details about message formatting.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felusivecodes%2Ffyrelog","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felusivecodes%2Ffyrelog","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felusivecodes%2Ffyrelog/lists"}