{"id":18458312,"url":"https://github.com/crazyfactory/phalcon-loggers","last_synced_at":"2025-07-03T15:08:13.475Z","repository":{"id":56958809,"uuid":"86789463","full_name":"crazyfactory/phalcon-loggers","owner":"crazyfactory","description":"Phalcon logging adapters for Slack and Sentry","archived":false,"fork":false,"pushed_at":"2022-12-30T12:10:38.000Z","size":42,"stargazers_count":7,"open_issues_count":1,"forks_count":1,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-05-26T17:12:39.985Z","etag":null,"topics":["adapter","logger","phalcon","sentry","slack"],"latest_commit_sha":null,"homepage":null,"language":"PHP","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/crazyfactory.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}},"created_at":"2017-03-31T07:12:49.000Z","updated_at":"2025-03-15T20:59:56.000Z","dependencies_parsed_at":"2023-01-31T11:31:06.518Z","dependency_job_id":null,"html_url":"https://github.com/crazyfactory/phalcon-loggers","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/crazyfactory/phalcon-loggers","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crazyfactory%2Fphalcon-loggers","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crazyfactory%2Fphalcon-loggers/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crazyfactory%2Fphalcon-loggers/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crazyfactory%2Fphalcon-loggers/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/crazyfactory","download_url":"https://codeload.github.com/crazyfactory/phalcon-loggers/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crazyfactory%2Fphalcon-loggers/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262198098,"owners_count":23273792,"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":["adapter","logger","phalcon","sentry","slack"],"created_at":"2024-11-06T08:17:48.424Z","updated_at":"2025-07-03T15:08:13.424Z","avatar_url":"https://github.com/crazyfactory.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"## phalcon-loggers ![build status](https://api.travis-ci.org/crazyfactory/phalcon-loggers.svg?branch=master)\n\nA collection of configurable logging adapters with logging functionality loosely PSR compatible for phalcon 3.x and PHP 7.x.\nCurrently the following adapters are implemented:\n\n#### Sentry\n- Depends on the [sentry/sentry](https://packagist.org/packages/sentry/sentry) package.\n- You have to run `composer require sentry/sentry`\n- You might have to require `Raven_Autoloader` as explained [here](https://docs.sentry.io/clients/php/#installation) (see #installation section below)\n- Disabled by default but is active if class `Raven_Client` is defined.\n\n#### Slack\n- Self contained and ready to work out of the box.\n\n*... and we plan to add a few more!*\n\n## Installation\nIt is a fully composer ready library. Just run:\n```\n$ composer require crazyfactory/phalcon-loggers\n```\n\nIf you have not used composer's autoloading (i.e. `require 'vendor/autoload.php'`) \u0026/or just want to use phalcon's native autoloader:\n```php\n$loader = new Phalcon\\Loader;\n$loader-\u003eregisterNamespaces([\n    'CrazyFactory\\\\PhalconLogger' =\u003e '/path/to/vendor/crazyfactory/phalcon-loggers/src/',\n])-\u003eregister();\n\n```\n\nIf you want to use Sentry as well:\n```\n$ composer require sentry/sentry\n```\n\nIf you have not used composer's autoloading, then setup autoloading of `Raven_` classes like so:\n```php\nrequire_once '/path/to/vendor/sentry/sentry/lib/Raven/Autoloader.php';\nRaven_Autoloader::register();\n```\n\n## Usage\n\nThe easiest and quickest way to use this library is by using the supplied `Service`:\n\n```php\n$id = (new Phalcon\\Security\\Random)-\u003euuid();\n$di = new Phalcon\\Di\\FactoryDefault;\n(new CrazyFactory\\PhalconLogger\\Service)-\u003eregister(null, $di);\n\n// If you already have `requestId` in config array/object you don't need to set it again.\n$di-\u003egetShared('logger')-\u003esetRequestId($id);\n\n$di-\u003egetShared('logger')-\u003einfo('some text');\n// Supports interpolation for keys wrapped in curly brace.\n$di-\u003egetShared('logger')-\u003ecritical('some text {key}', ['key' =\u003e 'val']);\n\n//\n// Below examples assume that info level is allowed in config-\u003eslack-\u003elevels array.\n//\n// Mention an user in slack:\n$context = ['mentions' =\u003e 'slackbot', 'a' =\u003e 10];\n$di-\u003egetShared('slack')-\u003einfo('some text {a}', $context);\n\n// Customize channel, username, icon_emoji, icon_url via context:\n$context += [\n    'username' =\u003e 'bot',\n    'channel' =\u003e '#general',\n    'icon_emoji' =\u003e ':monkey_face:',\n];\n$di-\u003egetShared('slack')-\u003einfo('some other text {a}', $context);\n\n// Attachment:\n$context += [\n    'attachment' =\u003e [\n        'title' =\u003e 'Attachment title',\n        'text' =\u003e 'Attachment text',\n        'color' =\u003e 'good',\n    ],\n];\n$di-\u003egetShared('slack')-\u003einfo('yet other text {a} with attachment', $context);\n```\n\nSee [examples](examples/) for details and various integration samples.\nAlso see the [API](#api) section.\n\n## Configuration\n\nYou can pass in configuration as an array or a file\nThe loggers have their own configuration options but share common parameter `requestId` and `environment`.\nHere is how a typical configuration looks like for slack and sentry both:\n\n```php\nuse Phalcon\\Logger;\n\n$config = [\n    // The application name used in logs. Helps to distinguish \u0026/or search.\n    'appName' =\u003e '',\n    // Current application environment.\n    'environment' =\u003e 'prod',\n    'requestID'   =\u003e null,\n    'sentry'      =\u003e [\n        // The login information for Sentry. If one of the values is empty the logging is suppressed silently.\n        'credential' =\u003e [\n            'key'       =\u003e '',\n            'secret'    =\u003e '',\n            'projectId' =\u003e '',\n        ],\n        // The options for Raven_Client. See https://docs.sentry.io/clients/php/config/#available-settings\n        'options' =\u003e [\n            'curl_method' =\u003e 'sync',\n            'prefixes'    =\u003e [],\n            'app_path'    =\u003e '',\n            'timeout'     =\u003e 2,\n        ],\n        // Sentry will log errors/exceptions when the application environment set above is one of these.\n        'environments' =\u003e ['prod', 'staging'],\n        // The log levels which are forwarded to sentry.\n        'levels' =\u003e [Logger::EMERGENCY, Logger::CRITICAL, Logger::ERROR],\n        // These exceptions are not reported to sentry.\n        'dontReport' =\u003e [],\n    ],\n    'slack' =\u003e [\n        // If webhook url is missing the logging is suppressed silently.\n        'webhookUrl'   =\u003e '',\n        // Slack will log messages when the application environment set above is one of these.\n        'environments' =\u003e ['prod', 'dev'],\n        // Curl method can be 'sync' or 'exec' (sync uses php curl_*, exec runs in background).\n        'curlMethod'   =\u003e 'sync',\n        // HTTP headers to be appended to request.\n        'headers'      =\u003e [],\n        // The log levels which are forwarded to slack.\n        'levels'       =\u003e [Logger::SPECIAL, Logger::CUSTOM],\n    ],\n];\n\n$di = new Phalcon\\Di\\FactoryDefault;\n\n// Register the loggers with the config:\n$di-\u003esetShared('sentry', function () use ($config) {\n    return new CrazyFactory\\PhalconLogger\\Adapter\\Sentry($config);\n});\n$di-\u003esetShared('slack', function () use ($config) {\n    return new CrazyFactory\\PhalconLogger\\Adapter\\Slack($config);\n});\n\n// OR you could just use supplied `Service`:\n(new CrazyFactory\\PhalconLogger\\Service)-\u003eregister($config, $di);\n\n```\n\n\n## \u003ca name=\"api\"\u003e\u003c/a\u003eAPI\nAll the loggers inherit from base phalcon logger [adapter](https://github.com/phalcon/cphalcon/blob/master/phalcon/logger/adapter.zep) so they automatically inherit public callable APIs from the base.\nIn addition the loggers may also expose some APIs available for direct call.\n\n#### Sentry:\nSentry logger has following public APIs:\n\n- **addCrumb(string $message, string $category = 'default', array $data = [], int $type = null)**\n```php\n    $di-\u003egetShared('sentry')-\u003eaddCrumb('User has just logged in');\n```\n\n- **setTag(string $key, string $value)**\n```php\n    $di-\u003egetShared('sentry')-\u003esetTag('name', 'value')-\u003esetTag('another', 'another-value');\n```\n\n- **setUserContext(array $context)**\n```php\n    // you can also use current user from DI if you have one\n    $di-\u003egetShared('sentry')-\u003esetUserContext(['id' =\u003e 1, 'username' =\u003e 'someone', 'email' =\u003e 'bob@example.com']);\n```\n\n- **setExtraContext(array $context)**\n```php\n    $di-\u003egetShared('sentry')-\u003esetExtraContext(['arbitrary_key' =\u003e 'arbitrary_value', 'arbitrary_key_2', 'arbitrary_value_2']);\n```\n\n- **getLastEventId()**\n```php\n    $di-\u003egetShared('sentry')-\u003egetLastEventId();\n```\n\n- **logException(\\Throwable $exception, array $context = [], int $type = null)**\n```php\n    try {\n        $app-\u003ehandle();\n    } catch (\\Throwable $e) {\n        $di-\u003egetShared('sentry')-\u003elogException($e);\n        // However it is advisable to just use logException of the logger collection\n        // so that all the registered loggers are notified of the exception to do the needful.\n        $di-\u003egetShared('logger')-\u003elogException($e);\n    }\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrazyfactory%2Fphalcon-loggers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcrazyfactory%2Fphalcon-loggers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrazyfactory%2Fphalcon-loggers/lists"}