ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
SamplingHandler.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
12namespace Monolog\Handler;
13
29{
33 protected $handler;
34
38 protected $factor;
39
44 public function __construct($handler, $factor)
45 {
46 parent::__construct();
47 $this->handler = $handler;
48 $this->factor = $factor;
49
50 if (!$this->handler instanceof HandlerInterface && !is_callable($this->handler)) {
51 throw new \RuntimeException("The given handler (".json_encode($this->handler).") is not a callable nor a Monolog\Handler\HandlerInterface object");
52 }
53 }
54
55 public function isHandling(array $record)
56 {
57 return $this->handler->isHandling($record);
58 }
59
60 public function handle(array $record)
61 {
62 if ($this->isHandling($record) && mt_rand(1, $this->factor) === 1) {
63 // The same logic as in FingersCrossedHandler
64 if (!$this->handler instanceof HandlerInterface) {
65 $this->handler = call_user_func($this->handler, $record, $this);
66 if (!$this->handler instanceof HandlerInterface) {
67 throw new \RuntimeException("The factory callable should return a HandlerInterface");
68 }
69 }
70
71 if ($this->processors) {
72 foreach ($this->processors as $processor) {
73 $record = call_user_func($processor, $record);
74 }
75 }
76
77 $this->handler->handle($record);
78 }
79
80 return false === $this->bubble;
81 }
82}
Base Handler class providing the Handler structure.
isHandling(array $record)
{{Checks whether the given record will be handled by this handler.This is mostly done for performance...
handle(array $record)
Handles a record.
Interface that all Monolog Handlers must implement.