ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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
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}
Monolog log channel.
Definition: Logger.php:28
static toMonologLevel($level)
Converts PSR-3 levels to Monolog ones if necessary.
Definition: Logger.php:403
const DEBUG
Detailed debug information.
Definition: Logger.php:32
Injects Git branch and Git commit SHA in all records.
__construct($level=Logger::DEBUG)
v($data, $pos)