Skip to content

Commit

Permalink
Fixed context.at in MonologAdapter
Browse files Browse the repository at this point in the history
  • Loading branch information
fprochazka committed Sep 8, 2014
1 parent 31eb03a commit 978c808
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
23 changes: 22 additions & 1 deletion src/Kdyby/Monolog/Diagnostics/MonologAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ public function __construct(Monolog\Logger $monolog)

public function log($message, $priority = self::INFO)
{
$context = array();
$normalised = $message;
$context = array(
'at' => self::getSource(),
);

if (is_array($message)) {
if (count($message) >= 2 && preg_match('~\\[[\\d+ -]+\\]~i', $message[0])) {
Expand Down Expand Up @@ -84,4 +86,23 @@ public function log($message, $priority = self::INFO)
}
}



/**
* @internal
* @author David Grudl
* @see https://github.com/nette/tracy/blob/922630e689578f6daae185dba251cded831d9162/src/Tracy/Helpers.php#L146
*/
protected static function getSource()
{
if (isset($_SERVER['REQUEST_URI'])) {
return (!empty($_SERVER['HTTPS']) && strcasecmp($_SERVER['HTTPS'], 'off') ? 'https://' : 'http://')
. (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '')
. $_SERVER['REQUEST_URI'];

} else {
return empty($_SERVER['argv']) ? 'CLI' : 'CLI: ' . implode(' ', $_SERVER['argv']);
}
}

}
8 changes: 4 additions & 4 deletions tests/KdybyTests/Monolog/Extension.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,15 @@ class ExtensionTest extends Tester\TestCase
$logger->addError('logger message 4', array('channel' => 'custom'));

Assert::match(
'[%a%] tracy message 1 [] []' . "\n" .
'[%a%] Exception: tracy exception message 2 in %a%:%d% {"tracy":"exception-%a%.html"} []' . "\n" .
'[%a%] tracy message 1 {"at":"%a%"} []' . "\n" .
'[%a%] Exception: tracy exception message 2 in %a%:%d% {"at":"%a%","tracy":"exception-%a%.html"} []' . "\n" .
'[%a%] logger message 1 [] []',
file_get_contents(TEMP_DIR . '/info.log')
);

Assert::match(
'[%a%] tracy message 2 [] []' . "\n" .
'[%a%] Exception: tracy exception message 1 in %a%:%d% {"tracy":"exception-%a%.html"} []' . "\n" .
'[%a%] tracy message 2 {"at":"%a%"} []' . "\n" .
'[%a%] Exception: tracy exception message 1 in %a%:%d% {"at":"%a%","tracy":"exception-%a%.html"} []' . "\n" .
'[%a%] logger message 3 [] []',
file_get_contents(TEMP_DIR . '/error.log')
);
Expand Down

0 comments on commit 978c808

Please sign in to comment.