-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from Seldaek/master
Update fork
- Loading branch information
Showing
10 changed files
with
250 additions
and
29 deletions.
There are no files selected for viewing
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Monolog package. | ||
* | ||
* (c) Jordi Boggiano <j.boggiano@seld.be> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Monolog\Processor; | ||
|
||
use Monolog\Logger; | ||
|
||
/** | ||
* Injects Git branch and Git commit SHA in all records | ||
* | ||
* @author Nick Otter | ||
* @author Jordi Boggiano <j.boggiano@seld.be> | ||
*/ | ||
class GitProcessor | ||
{ | ||
private $level; | ||
private static $cache; | ||
|
||
public function __construct($level = Logger::DEBUG) | ||
{ | ||
$this->level = $level; | ||
} | ||
|
||
/** | ||
* @param array $record | ||
* @return array | ||
*/ | ||
public function __invoke(array $record) | ||
{ | ||
// return if the level is not high enough | ||
if ($record['level'] < $this->level) { | ||
return $record; | ||
} | ||
|
||
$record['extra']['git'] = self::getGitInfo(); | ||
|
||
return $record; | ||
} | ||
|
||
private static function getGitInfo() | ||
{ | ||
if (self::$cache) { | ||
return self::$cache; | ||
} | ||
|
||
$branches = `git branch -v --no-abbrev`; | ||
if (preg_match('{^\* (.+?)\s+([a-f0-9]{40})(?:\s|$)}m', $branches, $matches)) { | ||
return self::$cache = array( | ||
'branch' => $matches[1], | ||
'commit' => $matches[2], | ||
); | ||
} | ||
|
||
return self::$cache = array(); | ||
} | ||
} |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Monolog package. | ||
* | ||
* (c) Jordi Boggiano <j.boggiano@seld.be> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Monolog; | ||
|
||
use InvalidArgumentException; | ||
|
||
/** | ||
* Monolog log registry | ||
* | ||
* Allows to get `Logger` instances in the global scope | ||
* via static method calls on this class. | ||
* | ||
* <code> | ||
* $application = new Monolog\Logger('application'); | ||
* $api = new Monolog\Logger('api'); | ||
* | ||
* Monolog\Registry::addLogger($application); | ||
* Monolog\Registry::addLogger($api); | ||
* | ||
* function testLogger() | ||
* { | ||
* Monolog\Registry::api()->addError('Sent to $api Logger instance'); | ||
* Monolog\Registry::application()->addError('Sent to $application Logger instance'); | ||
* } | ||
* </code> | ||
* | ||
* @author Tomas Tatarko <tomas@tatarko.sk> | ||
*/ | ||
class Registry | ||
{ | ||
/** | ||
* List of all loggers in the registry (ba named indexes) | ||
* | ||
* @var Logger[] | ||
*/ | ||
private static $loggers = array(); | ||
|
||
/** | ||
* Adds new logging channel to the registry | ||
* | ||
* @param Logger $logger Instance of the logging channel | ||
* @param string $name Name of the logging channel ($logger->getName() by default) | ||
* @param boolean $overwrite Overwrite instance in the registry if the given name already exists? | ||
* @throws \InvalidArgumentException If $overwrite set to false and named Logger instance already exists | ||
*/ | ||
public static function addLogger(Logger $logger, $name = null, $overwrite = false) | ||
{ | ||
$name = $name ?: $logger->getName(); | ||
|
||
if (isset(self::$loggers[$name]) && !$overwrite) { | ||
throw new InvalidArgumentException('Logger with the given name already exists'); | ||
} | ||
|
||
self::$loggers[$name] = $logger; | ||
} | ||
|
||
/** | ||
* Removes instance from registry by name or instance | ||
* | ||
* @param string|Logger $logger Name or logger instance | ||
*/ | ||
public static function removeLogger($logger) | ||
{ | ||
if ($logger instanceof Logger) { | ||
if (false !== ($idx = array_search($logger, self::$loggers, true))) { | ||
unset(self::$loggers[$idx]); | ||
} | ||
} else { | ||
unset(self::$loggers[$logger]); | ||
} | ||
} | ||
|
||
/** | ||
* Clears the registry | ||
*/ | ||
public static function clear() | ||
{ | ||
self::$loggers = array(); | ||
} | ||
|
||
/** | ||
* Gets Logger instance from the registry | ||
* | ||
* @param string $name Name of the requested Logger instance | ||
* @return Logger Requested instance of Logger | ||
* @throws \InvalidArgumentException If named Logger instance is not in the registry | ||
*/ | ||
public static function getInstance($name) | ||
{ | ||
if (!isset(self::$loggers[$name])) { | ||
throw new InvalidArgumentException(sprintf('Requested "%s" logger instance is not in the registry', $name)); | ||
} | ||
|
||
return self::$loggers[$name]; | ||
} | ||
|
||
/** | ||
* Gets Logger instance from the registry via static method call | ||
* | ||
* @param string $name Name of the requested Logger instance | ||
* @param array $arguments Arguments passed to static method call | ||
* @return Logger Requested instance of Logger | ||
* @throws \InvalidArgumentException If named Logger instance is not in the registry | ||
*/ | ||
public static function __callStatic($name, $arguments) | ||
{ | ||
return self::getInstance($name); | ||
} | ||
} |
Oops, something went wrong.