]> git.mxchange.org Git - friendica.git/blob - src/Core/Logger/Type/ProfilerLogger.php
Merge pull request #11129 from urbalazs/copyright-2022
[friendica.git] / src / Core / Logger / Type / ProfilerLogger.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2022, the Friendica project
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  *
20  */
21
22 namespace Friendica\Core\Logger\Type;
23
24 use Friendica\Util\Profiler;
25 use Psr\Log\LoggerInterface;
26
27 /**
28  * This Logger adds additional profiling data in case profiling is enabled.
29  * It uses a predefined logger.
30  */
31 class ProfilerLogger implements LoggerInterface
32 {
33         /**
34          * The Logger of the current call
35          * @var LoggerInterface
36          */
37         private $logger;
38
39         /**
40          * The Profiler for the current call
41          * @var Profiler
42          */
43         protected $profiler;
44
45         /**
46          * ProfilerLogger constructor.
47          * @param LoggerInterface $logger   The Logger of the current call
48          * @param Profiler        $profiler The profiler of the current call
49          */
50         public function __construct(LoggerInterface $logger, Profiler $profiler)
51         {
52                 $this->logger   = $logger;
53                 $this->profiler = $profiler;
54         }
55
56         /**
57          * {@inheritdoc}
58          */
59         public function emergency($message, array $context = [])
60         {
61                 $this->profiler->startRecording('file');
62                 $this->logger->emergency($message, $context);
63                 $this->profiler->stopRecording();
64         }
65
66         /**
67          * {@inheritdoc}
68          */
69         public function alert($message, array $context = [])
70         {
71                 $this->profiler->startRecording('file');
72                 $this->logger->alert($message, $context);
73                 $this->profiler->stopRecording();
74         }
75
76         /**
77          * {@inheritdoc}
78          */
79         public function critical($message, array $context = [])
80         {
81                 $this->profiler->startRecording('file');
82                 $this->logger->critical($message, $context);
83                 $this->profiler->stopRecording();
84         }
85
86         /**
87          * {@inheritdoc}
88          */
89         public function error($message, array $context = [])
90         {
91                 $this->profiler->startRecording('file');
92                 $this->logger->error($message, $context);
93                 $this->profiler->stopRecording();
94         }
95
96         /**
97          * {@inheritdoc}
98          */
99         public function warning($message, array $context = [])
100         {
101                 $this->profiler->startRecording('file');
102                 $this->logger->warning($message, $context);
103                 $this->profiler->stopRecording();
104         }
105
106         /**
107          * {@inheritdoc}
108          */
109         public function notice($message, array $context = [])
110         {
111                 $this->profiler->startRecording('file');
112                 $this->logger->notice($message, $context);
113                 $this->profiler->stopRecording();
114         }
115
116         /**
117          * {@inheritdoc}
118          */
119         public function info($message, array $context = [])
120         {
121                 $this->profiler->startRecording('file');
122                 $this->logger->info($message, $context);
123                 $this->profiler->stopRecording();
124         }
125
126         /**
127          * {@inheritdoc}
128          */
129         public function debug($message, array $context = [])
130         {
131                 $this->profiler->startRecording('file');
132                 $this->logger->debug($message, $context);
133                 $this->profiler->stopRecording();
134         }
135
136         /**
137          * {@inheritdoc}
138          */
139         public function log($level, $message, array $context = [])
140         {
141                 $this->profiler->startRecording('file');
142                 $this->logger->log($level, $message, $context);
143                 $this->profiler->stopRecording();
144         }
145 }