ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
MercurialProcessor.php
Go to the documentation of this file.
1<?php
2
3/*
4 * This file is part of the Monolog package.
5 *
6 * (c) Jonathan A. Schweder <jonathanschweder@gmail.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Monolog\Processor;
13
15
22{
23 private $level;
24 private static $cache;
25
26 public function __construct($level = Logger::DEBUG)
27 {
28 $this->level = Logger::toMonologLevel($level);
29 }
30
35 public function __invoke(array $record)
36 {
37 // return if the level is not high enough
38 if ($record['level'] < $this->level) {
39 return $record;
40 }
41
42 $record['extra']['hg'] = self::getMercurialInfo();
43
44 return $record;
45 }
46
47 private static function getMercurialInfo()
48 {
49 if (self::$cache) {
50 return self::$cache;
51 }
52
53 $result = explode(' ', trim(`hg id -nb`));
54 if (count($result) >= 3) {
55 return self::$cache = array(
56 'branch' => $result[1],
57 'revision' => $result[2],
58 );
59 }
60
61 return self::$cache = array();
62 }
63}
$result
An exception for terminatinating execution or to throw for unit testing.
Monolog log channel.
Definition: Logger.php:29
static toMonologLevel($level)
Converts PSR-3 levels to Monolog ones if necessary.
Definition: Logger.php:528
const DEBUG
Detailed debug information.
Definition: Logger.php:33
Injects Hg branch and Hg revision number in all records.
An optional interface to allow labelling Monolog processors.