From 99461622043e7d5858f45ca80c8d0b524c448491 Mon Sep 17 00:00:00 2001 From: James Van Lommel Date: Tue, 28 Apr 2015 13:38:24 -0700 Subject: [PATCH] Added documentation on how to fix browser console logging components. Uses Klein's afterDispatch() method, which is otherwise unmentioned in the Readme file or the PHPDocs. --- README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/README.md b/README.md index 6fafb862..a0cb890a 100644 --- a/README.md +++ b/README.md @@ -297,6 +297,22 @@ $this->sharedData()->get('myvar') // Access stored service variables echo $this->query(array('page' => 2)) // Modify the current query string ``` +## Headers Integration With Logging Services + +Logging services that send info to the browser console may fail when used with +Klein. They use HTTP headers for their data and need to send them ahead of when +Klein does. Klein provides a method to help with this: `$klein->afterDispatch($callable)`. + +Here is an example for the `BrowserConsoleHandler` from [Monolog](https://github.com/Seldaek/monolog), +though a similar pattern should work its `ChromePHPHandler` or `PHPConsoleHandler`. + +```php +$log = new Monolog\Logger('debug'); +$log->pushHandler(new Monolog\Handler\BrowserConsoleHandler()); + +$klein->afterDispatch(['\Monolog\Handler\BrowserConsoleHandler', 'send']); +``` + ## API Below is a list of the public methods in the common classes you will most likely use. For a more formal source