Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
10 / 10 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
Http | |
100.00% |
10 / 10 |
|
100.00% |
2 / 2 |
3 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
writeLog | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * Pop PHP Framework (http://www.popphp.org/) |
4 | * |
5 | * @link https://github.com/popphp/popphp-framework |
6 | * @author Nick Sagona, III <dev@nolainteractive.com> |
7 | * @copyright Copyright (c) 2009-2023 NOLA Interactive, LLC. (http://www.nolainteractive.com) |
8 | * @license http://www.popphp.org/license New BSD License |
9 | */ |
10 | |
11 | /** |
12 | * @namespace |
13 | */ |
14 | namespace Pop\Log\Writer; |
15 | |
16 | use Pop\Http\Client\Stream; |
17 | |
18 | /** |
19 | * Http log writer class |
20 | * |
21 | * @category Pop |
22 | * @package Pop\Log |
23 | * @author Nick Sagona, III <dev@nolainteractive.com> |
24 | * @copyright Copyright (c) 2009-2023 NOLA Interactive, LLC. (http://www.nolainteractive.com) |
25 | * @license http://www.popphp.org/license New BSD License |
26 | * @version 3.3.0 |
27 | */ |
28 | class Http extends AbstractWriter |
29 | { |
30 | |
31 | /** |
32 | * Stream object |
33 | * @var Stream |
34 | */ |
35 | protected $stream = null; |
36 | |
37 | /** |
38 | * Constructor |
39 | * |
40 | * Instantiate the Mail writer object |
41 | * |
42 | * @param Stream $stream |
43 | */ |
44 | public function __construct(Stream $stream) |
45 | { |
46 | $this->stream = $stream; |
47 | } |
48 | |
49 | /** |
50 | * Write to the log |
51 | * |
52 | * @param mixed $level |
53 | * @param string $message |
54 | * @param array $context |
55 | * @return Http |
56 | */ |
57 | public function writeLog($level, $message, array $context = []) |
58 | { |
59 | if ($this->isWithinLogLimit($level)) { |
60 | $timestamp = $context['timestamp']; |
61 | $name = $context['name']; |
62 | |
63 | unset($context['timestamp']); |
64 | unset($context['name']); |
65 | |
66 | $this->stream->setFields([ |
67 | 'timestamp' => $timestamp, |
68 | 'level' => $level, |
69 | 'name' => $name, |
70 | 'message' => $message, |
71 | 'context' => json_encode($context) |
72 | ]); |
73 | |
74 | $this->stream->send(); |
75 | } |
76 | |
77 | return $this; |
78 | } |
79 | |
80 | } |