]> git.mxchange.org Git - friendica.git/blob - src/Util/Logger/ProfilerLogger.php
Merge pull request #7248 from nupplaphil/bugs/6916-fatal-network
[friendica.git] / src / Util / Logger / ProfilerLogger.php
1 <?php
2
3 namespace Friendica\Util\Logger;
4
5 use Friendica\Core\System;
6 use Friendica\Util\Profiler;
7 use Psr\Log\LoggerInterface;
8
9 /**
10  * This Logger adds additional profiling data in case profiling is enabled.
11  * It uses a predefined logger.
12  */
13 class ProfilerLogger implements LoggerInterface
14 {
15         /**
16          * The Logger of the current call
17          * @var LoggerInterface
18          */
19         private $logger;
20
21         /**
22          * The Profiler for the current call
23          * @var Profiler
24          */
25         protected $profiler;
26
27         /**
28          * ProfilerLogger constructor.
29          * @param LoggerInterface $logger   The Logger of the current call
30          * @param Profiler        $profiler The profiler of the current call
31          */
32         public function __construct(LoggerInterface $logger, Profiler $profiler)
33         {
34                 $this->logger = $logger;
35                 $this->profiler = $profiler;
36         }
37
38         /**
39          * {@inheritdoc}
40          */
41         public function emergency($message, array $context = array())
42         {
43                 $stamp1 = microtime(true);
44                 $this->logger->emergency($message, $context);
45                 $this->profiler->saveTimestamp($stamp1, 'file', System::callstack());
46         }
47
48         /**
49          * {@inheritdoc}
50          */
51         public function alert($message, array $context = array())
52         {
53                 $stamp1 = microtime(true);
54                 $this->logger->alert($message, $context);
55                 $this->profiler->saveTimestamp($stamp1, 'file', System::callstack());
56         }
57
58         /**
59          * {@inheritdoc}
60          */
61         public function critical($message, array $context = array())
62         {
63                 $stamp1 = microtime(true);
64                 $this->logger->critical($message, $context);
65                 $this->profiler->saveTimestamp($stamp1, 'file', System::callstack());
66         }
67
68         /**
69          * {@inheritdoc}
70          */
71         public function error($message, array $context = array())
72         {
73                 $stamp1 = microtime(true);
74                 $this->logger->error($message, $context);
75                 $this->profiler->saveTimestamp($stamp1, 'file', System::callstack());
76         }
77
78         /**
79          * {@inheritdoc}
80          */
81         public function warning($message, array $context = array())
82         {
83                 $stamp1 = microtime(true);
84                 $this->logger->warning($message, $context);
85                 $this->profiler->saveTimestamp($stamp1, 'file', System::callstack());
86         }
87
88         /**
89          * {@inheritdoc}
90          */
91         public function notice($message, array $context = array())
92         {
93                 $stamp1 = microtime(true);
94                 $this->logger->notice($message, $context);
95                 $this->profiler->saveTimestamp($stamp1, 'file', System::callstack());
96         }
97
98         /**
99          * {@inheritdoc}
100          */
101         public function info($message, array $context = array())
102         {
103                 $stamp1 = microtime(true);
104                 $this->logger->info($message, $context);
105                 $this->profiler->saveTimestamp($stamp1, 'file', System::callstack());
106         }
107
108         /**
109          * {@inheritdoc}
110          */
111         public function debug($message, array $context = array())
112         {
113                 $stamp1 = microtime(true);
114                 $this->logger->debug($message, $context);
115                 $this->profiler->saveTimestamp($stamp1, 'file', System::callstack());
116         }
117
118         /**
119          * {@inheritdoc}
120          */
121         public function log($level, $message, array $context = array())
122         {
123                 $stamp1 = microtime(true);
124                 $this->logger->log($level, $message, $context);
125                 $this->profiler->saveTimestamp($stamp1, 'file', System::callstack());
126         }
127 }