MonologProcessorGitProcessor

Injects Git branch and Git commit SHA in all records.

Defined (1)

The class is defined in the following location(s).

/vendor/monolog/monolog/src/Monolog/Processor/GitProcessor.php  
  1. class GitProcessor 
  2. private $level; 
  3. private static $cache; 
  4.  
  5. public function __construct($level = Logger::DEBUG) 
  6. $this->level = Logger::toMonologLevel($level); 
  7.  
  8. /** 
  9. * @param array $record 
  10. * @return array 
  11. */ 
  12. public function __invoke(array $record) 
  13. // return if the level is not high enough 
  14. if ($record['level'] < $this->level) { 
  15. return $record; 
  16.  
  17. $record['extra']['git'] = self::getGitInfo(); 
  18.  
  19. return $record; 
  20.  
  21. private static function getGitInfo() 
  22. if (self::$cache) { 
  23. return self::$cache; 
  24.  
  25. $branches = `git branch -v --no-abbrev`; 
  26. if (preg_match('{^\* (.+?)\s+([a-f0-9]{40})(?:\s|$)}m', $branches, $matches)) { 
  27. return self::$cache = array( 
  28. 'branch' => $matches[1],  
  29. 'commit' => $matches[2],  
  30. ); 
  31.  
  32. return self::$cache = array();