ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
GitProcessor.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the Monolog package.
5  *
6  * (c) Jordi Boggiano <j.boggiano@seld.be>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11 
13 
14 use Monolog\Logger;
15 
23 {
24  private $level;
25  private static $cache;
26 
27  public function __construct($level = Logger::DEBUG)
28  {
29  $this->level = Logger::toMonologLevel($level);
30  }
31 
36  public function __invoke(array $record)
37  {
38  // return if the level is not high enough
39  if ($record['level'] < $this->level) {
40  return $record;
41  }
42 
43  $record['extra']['git'] = self::getGitInfo();
44 
45  return $record;
46  }
47 
48  private static function getGitInfo()
49  {
50  if (self::$cache) {
51  return self::$cache;
52  }
53 
54  $branches = `git branch -v --no-abbrev`;
55  if (preg_match('{^\* (.+?)\s+([a-f0-9]{40})(?:\s|$)}m', $branches, $matches)) {
56  return self::$cache = array(
57  'branch' => $matches[1],
58  'commit' => $matches[2],
59  );
60  }
61 
62  return self::$cache = array();
63  }
64 }
const DEBUG
Detailed debug information.
Definition: Logger.php:32
static toMonologLevel($level)
Converts PSR-3 levels to Monolog ones if necessary.
Definition: Logger.php:473
Create styles array
The data for the language used.
__construct($level=Logger::DEBUG)
Injects Git branch and Git commit SHA in all records.