Created
December 12, 2014 13:33
-
-
Save levacic/f7f7e8c152cf24e39952 to your computer and use it in GitHub Desktop.
Revisions
-
levacic created this gist
Dec 12, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,48 @@ <?php namespace Creitive\Monolog\Processor; /** * Injects arbitrary extra data in all records. * * @author Miloš Levačić <[email protected]> */ class ExtraDataProcessor { /** * @var array */ protected $extraData = array(); /** * @param array $extraData Extra data to be added */ public function __construct(array $extraData = array()) { $this->extraData = $extraData; } /** * @param array $record * @return array */ public function __invoke(array $record) { $record['extra'] = $this->appendExtraFields($record['extra']); return $record; } /** * @param array $extra * @return array */ private function appendExtraFields(array $extra) { foreach ($this->extraData as $key => $value) { $extra[$key] = $value; } return $extra; } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,11 @@ $extraDataProcessor = new Creitive\Monolog\Processor\ExtraDataProcessor([ 'httpMethod' => Request::method(), 'url' => Request::url(), 'environment' => App::environment(), 'console' => App::runningInConsole(), 'clientIps' => Request::getClientIps(), 'referrer' => Request::server('HTTP_REFERER'), 'userAgent' => Request::header('User-Agent'), ]); $monolog->pushProcessor($extraDataProcessor);