1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
/** |
3
|
|
|
* ownCloud |
4
|
|
|
* |
5
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
6
|
|
|
* later. See the COPYING file. |
7
|
|
|
* |
8
|
|
|
* @author Alessandro Cosentino <[email protected]> |
9
|
|
|
* @author Bernhard Posselt <[email protected]> |
10
|
|
|
* @author Pauli Järvinen <[email protected]> |
11
|
|
|
* @copyright Alessandro Cosentino 2012 |
12
|
|
|
* @copyright Bernhard Posselt 2012, 2014 |
13
|
|
|
* @copyright Pauli Järvinen 2018 - 2025 |
14
|
|
|
*/ |
15
|
|
|
|
16
|
|
|
namespace OCA\Music\AppFramework\Core; |
17
|
|
|
|
18
|
|
|
use OCP\IServerContainer; |
19
|
|
|
|
20
|
|
|
class Logger { |
21
|
|
|
|
22
|
|
|
protected string $appName; |
23
|
|
|
/** @var \OCP\ILogger|\Psr\Log\LoggerInterface $logger */ |
24
|
|
|
protected $logger; |
25
|
|
|
|
26
|
|
|
public function __construct(string $appName, IServerContainer $container) { |
27
|
|
|
$this->appName = $appName; |
28
|
|
|
|
29
|
|
|
// NC 31 removed the getLogger method but the Psr alternative is not available on OC |
30
|
|
|
if (\method_exists($container, 'getLogger')) { // @phpstan-ignore function.alreadyNarrowedType |
31
|
|
|
$this->logger = $container->getLogger(); |
|
|
|
|
32
|
|
|
} else { |
33
|
|
|
$this->logger = $container->get(\Psr\Log\LoggerInterface::class); |
34
|
|
|
} |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function emergency(string $message) : void |
38
|
|
|
{ |
39
|
|
|
$this->logger->emergency($message, ['app' => $this->appName]); |
|
|
|
|
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Action must be taken immediately. |
44
|
|
|
*/ |
45
|
|
|
public function alert(string $message) : void |
46
|
|
|
{ |
47
|
|
|
$this->logger->alert($message, ['app' => $this->appName]); |
|
|
|
|
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Critical conditions. |
52
|
|
|
*/ |
53
|
|
|
public function critical(string $message) : void |
54
|
|
|
{ |
55
|
|
|
$this->logger->critical($message, ['app' => $this->appName]); |
|
|
|
|
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Runtime errors that do not require immediate action but should typically |
60
|
|
|
* be logged and monitored. |
61
|
|
|
*/ |
62
|
|
|
public function error(string $message) : void |
63
|
|
|
{ |
64
|
|
|
$this->logger->error($message, ['app' => $this->appName]); |
|
|
|
|
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Exceptional occurrences that are not errors. |
69
|
|
|
*/ |
70
|
|
|
public function warning(string $message) : void |
71
|
|
|
{ |
72
|
|
|
$this->logger->warning($message, ['app' => $this->appName]); |
|
|
|
|
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Normal but significant events. |
77
|
|
|
*/ |
78
|
|
|
public function notice(string $message) : void |
79
|
|
|
{ |
80
|
|
|
$this->logger->notice($message, ['app' => $this->appName]); |
|
|
|
|
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Interesting events. |
85
|
|
|
*/ |
86
|
|
|
public function info(string $message) : void |
87
|
|
|
{ |
88
|
|
|
$this->logger->info($message, ['app' => $this->appName]); |
|
|
|
|
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Detailed debug information. |
93
|
|
|
*/ |
94
|
|
|
public function debug(string $message) : void |
95
|
|
|
{ |
96
|
|
|
$this->logger->debug($message, ['app' => $this->appName]); |
|
|
|
|
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
} |
100
|
|
|
|
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.