Update copyright
[friendica.git/.git] / src / Util / Logger / ProfilerLogger.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2021, 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\Util\Logger;
23
24 use Friendica\Core\System;
25 use Friendica\Util\Profiler;
26 use Psr\Log\LoggerInterface;
27
28 /**
29  * This Logger adds additional profiling data in case profiling is enabled.
30  * It uses a predefined logger.
31  */
32 class ProfilerLogger implements LoggerInterface
33 {
34         /**
35          * The Logger of the current call
36          * @var LoggerInterface
37          */
38         private $logger;
39
40         /**
41          * The Profiler for the current call
42          * @var Profiler
43          */
44         protected $profiler;
45
46         /**
47          * ProfilerLogger constructor.
48          * @param LoggerInterface $logger   The Logger of the current call
49          * @param Profiler        $profiler The profiler of the current call
50          */
51         public function __construct(LoggerInterface $logger, Profiler $profiler)
52         {
53                 $this->logger = $logger;
54                 $this->profiler = $profiler;
55         }
56
57         /**
58          * {@inheritdoc}
59          */
60         public function emergency($message, array $context = array())
61         {
62                 $stamp1 = microtime(true);
63                 $this->logger->emergency($message, $context);
64                 $this->profiler->saveTimestamp($stamp1, 'file');
65         }
66
67         /**
68          * {@inheritdoc}
69          */
70         public function alert($message, array $context = array())
71         {
72                 $stamp1 = microtime(true);
73                 $this->logger->alert($message, $context);
74                 $this->profiler->saveTimestamp($stamp1, 'file');
75         }
76
77         /**
78          * {@inheritdoc}
79          */
80         public function critical($message, array $context = array())
81         {
82                 $stamp1 = microtime(true);
83                 $this->logger->critical($message, $context);
84                 $this->profiler->saveTimestamp($stamp1, 'file');
85         }
86
87         /**
88          * {@inheritdoc}
89          */
90         public function error($message, array $context = array())
91         {
92                 $stamp1 = microtime(true);
93                 $this->logger->error($message, $context);
94                 $this->profiler->saveTimestamp($stamp1, 'file');
95         }
96
97         /**
98          * {@inheritdoc}
99          */
100         public function warning($message, array $context = array())
101         {
102                 $stamp1 = microtime(true);
103                 $this->logger->warning($message, $context);
104                 $this->profiler->saveTimestamp($stamp1, 'file');
105         }
106
107         /**
108          * {@inheritdoc}
109          */
110         public function notice($message, array $context = array())
111         {
112                 $stamp1 = microtime(true);
113                 $this->logger->notice($message, $context);
114                 $this->profiler->saveTimestamp($stamp1, 'file');
115         }
116
117         /**
118          * {@inheritdoc}
119          */
120         public function info($message, array $context = array())
121         {
122                 $stamp1 = microtime(true);
123                 $this->logger->info($message, $context);
124                 $this->profiler->saveTimestamp($stamp1, 'file');
125         }
126
127         /**
128          * {@inheritdoc}
129          */
130         public function debug($message, array $context = array())
131         {
132                 $stamp1 = microtime(true);
133                 $this->logger->debug($message, $context);
134                 $this->profiler->saveTimestamp($stamp1, 'file');
135         }
136
137         /**
138          * {@inheritdoc}
139          */
140         public function log($level, $message, array $context = array())
141         {
142                 $stamp1 = microtime(true);
143                 $this->logger->log($level, $message, $context);
144                 $this->profiler->saveTimestamp($stamp1, 'file');
145         }
146 }