123456 |
- {
- "html": "<div class=\"section\" id=\"installation\">\n<h2>Installation</h2>\n<p>There are various ways to install the PHP integration for Sentry. The\nrecommended way is to use <a class=\"reference external\" href=\"http://getcomposer.org/\">Composer</a>:</p>\n<div class=\"highlight-python\"><div class=\"highlight\" style=\"background: #ffffff\"><pre style=\"line-height: 125%\"><span></span>$ composer require "sentry/sentry"\n</pre></div>\n</div>\n<p>Alternatively you can manually install it:</p>\n<ol class=\"arabic\">\n<li><p class=\"first\">Download and extract the latest <a class=\"reference external\" href=\"https://github.com/getsentry/sentry-php/archive/master.zip\">sentry-php</a> archive\nto your PHP project.</p>\n</li>\n<li><p class=\"first\">Require the autoloader in your application:</p>\n<div class=\"highlight-php\"><div class=\"highlight\" style=\"background: #ffffff\"><pre style=\"line-height: 125%\"><span></span><span style=\"color: #2eb0f7\">require_once</span> <span style=\"color: #e8535a\">'/path/to/Raven/library/Raven/Autoloader.php'</span><span style=\"color: #111111\">;</span>\n<span style=\"color: #111111\">Raven_Autoloader</span><span style=\"color: #4b4f5c\">::</span><span style=\"color: #a47ac6\">register</span><span style=\"color: #111111\">();</span>\n</pre></div>\n</div>\n</li>\n</ol>\n</div>\n\n\n<div class=\"section\" id=\"monolog\">\n<h2>Monolog</h2>\n<div class=\"section\" id=\"capturing-errors\">\n<h3>Capturing Errors</h3>\n<p>Monolog supports Sentry out of the box, so you’ll just need to configure a handler:</p>\n<div class=\"highlight-php\"><div class=\"highlight\" style=\"background: #ffffff\"><pre style=\"line-height: 125%\"><span></span><span style=\"color: #111111\">$client</span> <span style=\"color: #4b4f5c\">=</span> <span style=\"color: #2eb0f7\">new</span> <span style=\"color: #111111\">Raven_Client(</span><span style=\"color: #e8535a\">'___DSN___'</span><span style=\"color: #111111\">);</span>\n\n<span style=\"color: #111111\">$handler</span> <span style=\"color: #4b4f5c\">=</span> <span style=\"color: #2eb0f7\">new</span> <span style=\"color: #111111\">Monolog\\Handler\\RavenHandler($client);</span>\n<span style=\"color: #111111\">$handler</span><span style=\"color: #4b4f5c\">-></span><span style=\"color: #a47ac6\">setFormatter</span><span style=\"color: #111111\">(</span><span style=\"color: #2eb0f7\">new</span> <span style=\"color: #111111\">Monolog\\Formatter\\LineFormatter(</span><span style=\"color: #e8535a\">"%message% %context% %extra%\\n"</span><span style=\"color: #111111\">));</span>\n\n<span style=\"color: #111111\">$monolog</span><span style=\"color: #4b4f5c\">-></span><span style=\"color: #a47ac6\">pushHandler</span><span style=\"color: #111111\">($handler);</span>\n</pre></div>\n</div>\n</div>\n<div class=\"section\" id=\"adding-context\">\n<h3>Adding Context</h3>\n<p>Capturing context can be done via a monolog processor:</p>\n<div class=\"highlight-php\"><div class=\"highlight\" style=\"background: #ffffff\"><pre style=\"line-height: 125%\"><span></span><span style=\"color: #111111\">$monolog</span><span style=\"color: #4b4f5c\">-></span><span style=\"color: #a47ac6\">pushProcessor</span><span style=\"color: #111111\">(</span><span style=\"color: #2eb0f7\">function</span> <span style=\"color: #111111\">($record)</span> <span style=\"color: #111111\">{</span>\n <span style=\"color: #34c08b; font-style: italic\">// record the current user</span>\n <span style=\"color: #111111\">$user</span> <span style=\"color: #4b4f5c\">=</span> <span style=\"color: #111111\">Acme</span><span style=\"color: #4b4f5c\">::</span><span style=\"color: #a47ac6\">getCurrentUser</span><span style=\"color: #111111\">();</span>\n <span style=\"color: #111111\">$record[</span><span style=\"color: #e8535a\">'context'</span><span style=\"color: #111111\">][</span><span style=\"color: #e8535a\">'user'</span><span style=\"color: #111111\">]</span> <span style=\"color: #4b4f5c\">=</span> <span style=\"color: #2eb0f7\">array</span><span style=\"color: #111111\">(</span>\n <span style=\"color: #e8535a\">'name'</span> <span style=\"color: #4b4f5c\">=></span> <span style=\"color: #111111\">$user</span><span style=\"color: #4b4f5c\">-></span><span style=\"color: #a47ac6\">getName</span><span style=\"color: #111111\">(),</span>\n <span style=\"color: #e8535a\">'username'</span> <span style=\"color: #4b4f5c\">=></span> <span style=\"color: #111111\">$user</span><span style=\"color: #4b4f5c\">-></span><span style=\"color: #a47ac6\">getUsername</span><span style=\"color: #111111\">(),</span>\n <span style=\"color: #e8535a\">'email'</span> <span style=\"color: #4b4f5c\">=></span> <span style=\"color: #111111\">$user</span><span style=\"color: #4b4f5c\">-></span><span style=\"color: #a47ac6\">getEmail</span><span style=\"color: #111111\">(),</span>\n <span style=\"color: #111111\">);</span>\n\n <span style=\"color: #34c08b; font-style: italic\">// Add various tags</span>\n <span style=\"color: #111111\">$record[</span><span style=\"color: #e8535a\">'context'</span><span style=\"color: #111111\">][</span><span style=\"color: #e8535a\">'tags'</span><span style=\"color: #111111\">]</span> <span style=\"color: #4b4f5c\">=</span> <span style=\"color: #2eb0f7\">array</span><span style=\"color: #111111\">(</span><span style=\"color: #e8535a\">'key'</span> <span style=\"color: #4b4f5c\">=></span> <span style=\"color: #e8535a\">'value'</span><span style=\"color: #111111\">);</span>\n\n <span style=\"color: #34c08b; font-style: italic\">// Add various generic context</span>\n <span style=\"color: #111111\">$record[</span><span style=\"color: #e8535a\">'extra'</span><span style=\"color: #111111\">][</span><span style=\"color: #e8535a\">'key'</span><span style=\"color: #111111\">]</span> <span style=\"color: #4b4f5c\">=</span> <span style=\"color: #e8535a\">'value'</span><span style=\"color: #111111\">;</span>\n\n <span style=\"color: #2eb0f7\">return</span> <span style=\"color: #111111\">$record;</span>\n<span style=\"color: #111111\">});</span>\n</pre></div>\n</div>\n</div>\n<div class=\"section\" id=\"breadcrumbs\">\n<h3>Breadcrumbs</h3>\n<p>Sentry provides a breadcrumb handler to automatically send logs along as crumbs:</p>\n<div class=\"highlight-php\"><div class=\"highlight\" style=\"background: #ffffff\"><pre style=\"line-height: 125%\"><span></span><span style=\"color: #111111\">$client</span> <span style=\"color: #4b4f5c\">=</span> <span style=\"color: #2eb0f7\">new</span> <span style=\"color: #111111\">Raven_Client(</span><span style=\"color: #e8535a\">'___DSN___'</span><span style=\"color: #111111\">);</span>\n\n<span style=\"color: #111111\">$handler</span> <span style=\"color: #4b4f5c\">=</span> <span style=\"color: #2eb0f7\">new</span> <span style=\"color: #111111\">\\Raven_Breadcrumbs_MonologHandler($client);</span>\n<span style=\"color: #111111\">$monolog</span><span style=\"color: #4b4f5c\">-></span><span style=\"color: #a47ac6\">pushHandler</span><span style=\"color: #111111\">($handler);</span>\n</pre></div>\n</div>\n</div>\n</div>\n",
- "link": "https://docs.getsentry.com/clients/php/integrations/monolog/",
- "id": "php-monolog",
- "name": "Monolog"
- }
|