4 * This file is part of the Monolog package.
6 * (c) Jonathan A. Schweder <jonathanschweder@gmail.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Monolog\Processor;
17 * Injects Hg branch and Hg revision number in all records
19 * @author Jonathan A. Schweder <jonathanschweder@gmail.com>
21 class MercurialProcessor
24 private static $cache;
26 public function __construct($level = Logger::DEBUG)
28 $this->level = Logger::toMonologLevel($level);
32 * @param array $record
35 public function __invoke(array $record)
37 // return if the level is not high enough
38 if ($record['level'] < $this->level) {
42 $record['extra']['hg'] = self::getMercurialInfo();
47 private static function getMercurialInfo()
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],
61 return self::$cache = array();