scratch – Blame information for rev 115

Subversion Repositories:
Rev:
Rev Author Line No. Line
115 office 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  
12 namespace Monolog\Handler\FingersCrossed;
13  
14 use Monolog\Logger;
15  
16 /**
17 * Channel and Error level based monolog activation strategy. Allows to trigger activation
18 * based on level per channel. e.g. trigger activation on level 'ERROR' by default, except
19 * for records of the 'sql' channel; those should trigger activation on level 'WARN'.
20 *
21 * Example:
22 *
23 * <code>
24 * $activationStrategy = new ChannelLevelActivationStrategy(
25 * Logger::CRITICAL,
26 * array(
27 * 'request' => Logger::ALERT,
28 * 'sensitive' => Logger::ERROR,
29 * )
30 * );
31 * $handler = new FingersCrossedHandler(new StreamHandler('php://stderr'), $activationStrategy);
32 * </code>
33 *
34 * @author Mike Meessen <netmikey@gmail.com>
35 */
36 class ChannelLevelActivationStrategy implements ActivationStrategyInterface
37 {
38 private $defaultActionLevel;
39 private $channelToActionLevel;
40  
41 /**
42 * @param int $defaultActionLevel The default action level to be used if the record's category doesn't match any
43 * @param array $channelToActionLevel An array that maps channel names to action levels.
44 */
45 public function __construct($defaultActionLevel, $channelToActionLevel = array())
46 {
47 $this->defaultActionLevel = Logger::toMonologLevel($defaultActionLevel);
48 $this->channelToActionLevel = array_map('Monolog\Logger::toMonologLevel', $channelToActionLevel);
49 }
50  
51 public function isHandlerActivated(array $record)
52 {
53 if (isset($this->channelToActionLevel[$record['channel']])) {
54 return $record['level'] >= $this->channelToActionLevel[$record['channel']];
55 }
56  
57 return $record['level'] >= $this->defaultActionLevel;
58 }
59 }