1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Copyright 2014 SURFnet bv |
5
|
|
|
* |
6
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
7
|
|
|
* you may not use this file except in compliance with the License. |
8
|
|
|
* You may obtain a copy of the License at |
9
|
|
|
* |
10
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
11
|
|
|
* |
12
|
|
|
* Unless required by applicable law or agreed to in writing, software |
13
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
14
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
15
|
|
|
* See the License for the specific language governing permissions and |
16
|
|
|
* limitations under the License. |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
namespace Surfnet\StepupBundle\Monolog\Handler; |
20
|
|
|
|
21
|
|
|
use Monolog\Formatter\FormatterInterface; |
22
|
|
|
use Monolog\Handler\HandlerInterface; |
23
|
|
|
use Monolog\Handler\StreamHandler; |
24
|
|
|
use Surfnet\StepupBundle\Exception\CannotWriteToPrimaryLogException; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Represents StepUp's primary log handler. Transforms the exception thrown by StreamHandlers when the stream cannot be |
28
|
|
|
* written to. |
29
|
|
|
*/ |
30
|
|
|
class PrimaryLogHandler implements HandlerInterface |
31
|
|
|
{ |
32
|
|
|
/** |
33
|
|
|
* @var StreamHandler |
34
|
|
|
*/ |
35
|
|
|
private $streamHandler; |
36
|
|
|
|
37
|
|
|
public function handle(array $record) |
38
|
|
|
{ |
39
|
|
|
try { |
40
|
|
|
$this->streamHandler->handle($record); |
41
|
|
|
} catch (\UnexpectedValueException $e) { |
42
|
|
|
throw new CannotWriteToPrimaryLogException( |
43
|
|
|
sprintf('Cannot write to primary log: %s', $e->getMessage()), |
44
|
|
|
0, |
45
|
|
|
$e |
46
|
|
|
); |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function isHandling(array $record) |
51
|
|
|
{ |
52
|
|
|
return $this->streamHandler->isHandling($record); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function handleBatch(array $records) |
56
|
|
|
{ |
57
|
|
|
return $this->streamHandler->handleBatch($records); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function pushProcessor($callback) |
61
|
|
|
{ |
62
|
|
|
return $this->streamHandler->pushProcessor($callback); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function popProcessor() |
66
|
|
|
{ |
67
|
|
|
return $this->streamHandler->popProcessor(); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function setFormatter(FormatterInterface $formatter) |
71
|
|
|
{ |
72
|
|
|
return $this->streamHandler->setFormatter($formatter); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function getFormatter() |
76
|
|
|
{ |
77
|
|
|
return $this->streamHandler->getFormatter(); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|