Skip to content

Commit 09e6b26

Browse files
authored
Merge pull request #21875 from nextcloud/techdebt/deprecate-ilogger
Deprecate ILogger in favor of the PSR-3 logger
2 parents 8a229d6 + b3b856c commit 09e6b26

File tree

3 files changed

+60
-7
lines changed

3 files changed

+60
-7
lines changed

apps/contactsinteraction/lib/Listeners/ContactInteractionListener.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
use OCP\EventDispatcher\Event;
3434
use OCP\EventDispatcher\IEventListener;
3535
use OCP\IL10N;
36-
use OCP\ILogger;
3736
use OCP\IUserManager;
37+
use Psr\Log\LoggerInterface;
3838
use Sabre\VObject\Component\VCard;
3939
use Sabre\VObject\Reader;
4040
use Sabre\VObject\UUIDUtil;
@@ -57,15 +57,15 @@ class ContactInteractionListener implements IEventListener {
5757
/** @var IL10N */
5858
private $l10n;
5959

60-
/** @var ILogger */
60+
/** @var LoggerInterface */
6161
private $logger;
6262

6363
public function __construct(RecentContactMapper $mapper,
6464
CardSearchDao $cardSearchDao,
6565
IUserManager $userManager,
6666
ITimeFactory $timeFactory,
6767
IL10N $l10nFactory,
68-
ILogger $logger) {
68+
LoggerInterface $logger) {
6969
$this->mapper = $mapper;
7070
$this->cardSearchDao = $cardSearchDao;
7171
$this->userManager = $userManager;
@@ -125,10 +125,11 @@ public function handle(Event $event): void {
125125
$parsed->CATEGORIES = $this->l10n->t('Recently contacted');
126126
$contact->setCard($parsed->serialize());
127127
} catch (Throwable $e) {
128-
$this->logger->logException($e, [
129-
'message' => 'Could not parse card to add recent category: ' . $e->getMessage(),
130-
'level' => ILogger::WARN,
131-
]);
128+
$this->logger->warning(
129+
'Could not parse card to add recent category: ' . $e->getMessage(),
130+
[
131+
'exception' => $e,
132+
]);
132133
$contact->setCard($copy);
133134
}
134135
} else {

lib/private/AppFramework/Logger.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828

2929
use OCP\ILogger;
3030

31+
/**
32+
* @deprecated
33+
*/
3134
class Logger implements ILogger {
3235

3336
/** @var ILogger */
@@ -36,6 +39,9 @@ class Logger implements ILogger {
3639
/** @var string */
3740
private $appName;
3841

42+
/**
43+
* @deprecated
44+
*/
3945
public function __construct(ILogger $logger, string $appName) {
4046
$this->logger = $logger;
4147
$this->appName = $appName;
@@ -49,42 +55,72 @@ private function extendContext(array $context): array {
4955
return $context;
5056
}
5157

58+
/**
59+
* @deprecated
60+
*/
5261
public function emergency(string $message, array $context = []) {
5362
$this->logger->emergency($message, $this->extendContext($context));
5463
}
5564

65+
/**
66+
* @deprecated
67+
*/
5668
public function alert(string $message, array $context = []) {
5769
$this->logger->alert($message, $this->extendContext($context));
5870
}
5971

72+
/**
73+
* @deprecated
74+
*/
6075
public function critical(string $message, array $context = []) {
6176
$this->logger->critical($message, $this->extendContext($context));
6277
}
6378

79+
/**
80+
* @deprecated
81+
*/
6482
public function error(string $message, array $context = []) {
6583
$this->logger->emergency($message, $this->extendContext($context));
6684
}
6785

86+
/**
87+
* @deprecated
88+
*/
6889
public function warning(string $message, array $context = []) {
6990
$this->logger->warning($message, $this->extendContext($context));
7091
}
7192

93+
/**
94+
* @deprecated
95+
*/
7296
public function notice(string $message, array $context = []) {
7397
$this->logger->notice($message, $this->extendContext($context));
7498
}
7599

100+
/**
101+
* @deprecated
102+
*/
76103
public function info(string $message, array $context = []) {
77104
$this->logger->info($message, $this->extendContext($context));
78105
}
79106

107+
/**
108+
* @deprecated
109+
*/
80110
public function debug(string $message, array $context = []) {
81111
$this->logger->debug($message, $this->extendContext($context));
82112
}
83113

114+
/**
115+
* @deprecated
116+
*/
84117
public function log(int $level, string $message, array $context = []) {
85118
$this->logger->log($level, $message, $this->extendContext($context));
86119
}
87120

121+
/**
122+
* @deprecated
123+
*/
88124
public function logException(\Throwable $exception, array $context = []) {
89125
$this->logger->logException($exception, $this->extendContext($context));
90126
}

lib/public/ILogger.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,26 +39,32 @@
3939
*
4040
* This logger interface follows the design guidelines of PSR-3
4141
* https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md#3-psrlogloggerinterface
42+
* @deprecated 20.0.0 use the PSR-3 logger \Psr\Log\LoggerInterface
4243
*/
4344
interface ILogger {
4445
/**
4546
* @since 14.0.0
47+
* @deprecated 20.0.0
4648
*/
4749
public const DEBUG=0;
4850
/**
4951
* @since 14.0.0
52+
* @deprecated 20.0.0
5053
*/
5154
public const INFO=1;
5255
/**
5356
* @since 14.0.0
57+
* @deprecated 20.0.0
5458
*/
5559
public const WARN=2;
5660
/**
5761
* @since 14.0.0
62+
* @deprecated 20.0.0
5863
*/
5964
public const ERROR=3;
6065
/**
6166
* @since 14.0.0
67+
* @deprecated 20.0.0
6268
*/
6369
public const FATAL=4;
6470

@@ -69,6 +75,7 @@ interface ILogger {
6975
* @param array $context
7076
* @return null
7177
* @since 7.0.0
78+
* @deprecated 20.0.0 use \Psr\Log\LoggerInterface::emergency
7279
*/
7380
public function emergency(string $message, array $context = []);
7481

@@ -79,6 +86,7 @@ public function emergency(string $message, array $context = []);
7986
* @param array $context
8087
* @return null
8188
* @since 7.0.0
89+
* @deprecated 20.0.0 use \Psr\Log\LoggerInterface::alert
8290
*/
8391
public function alert(string $message, array $context = []);
8492

@@ -89,6 +97,7 @@ public function alert(string $message, array $context = []);
8997
* @param array $context
9098
* @return null
9199
* @since 7.0.0
100+
* @deprecated 20.0.0 use \Psr\Log\LoggerInterface::critical
92101
*/
93102
public function critical(string $message, array $context = []);
94103

@@ -100,6 +109,7 @@ public function critical(string $message, array $context = []);
100109
* @param array $context
101110
* @return null
102111
* @since 7.0.0
112+
* @deprecated 20.0.0 use \Psr\Log\LoggerInterface::error
103113
*/
104114
public function error(string $message, array $context = []);
105115

@@ -110,6 +120,7 @@ public function error(string $message, array $context = []);
110120
* @param array $context
111121
* @return null
112122
* @since 7.0.0
123+
* @deprecated 20.0.0 use \Psr\Log\LoggerInterface::warning
113124
*/
114125
public function warning(string $message, array $context = []);
115126

@@ -120,6 +131,7 @@ public function warning(string $message, array $context = []);
120131
* @param array $context
121132
* @return null
122133
* @since 7.0.0
134+
* @deprecated 20.0.0 use \Psr\Log\LoggerInterface::notice
123135
*/
124136
public function notice(string $message, array $context = []);
125137

@@ -130,6 +142,7 @@ public function notice(string $message, array $context = []);
130142
* @param array $context
131143
* @return null
132144
* @since 7.0.0
145+
* @deprecated 20.0.0 use \Psr\Log\LoggerInterface::info
133146
*/
134147
public function info(string $message, array $context = []);
135148

@@ -140,6 +153,7 @@ public function info(string $message, array $context = []);
140153
* @param array $context
141154
* @return null
142155
* @since 7.0.0
156+
* @deprecated 20.0.0 use \Psr\Log\LoggerInterface::debug
143157
*/
144158
public function debug(string $message, array $context = []);
145159

@@ -151,6 +165,7 @@ public function debug(string $message, array $context = []);
151165
* @param array $context
152166
* @return mixed
153167
* @since 7.0.0
168+
* @deprecated 20.0.0 use \Psr\Log\LoggerInterface::log
154169
*/
155170
public function log(int $level, string $message, array $context = []);
156171

@@ -169,6 +184,7 @@ public function log(int $level, string $message, array $context = []);
169184
* @param array $context
170185
* @return void
171186
* @since 8.2.0
187+
* @deprecated 20.0.0 use the `exception` entry in the context of any method in \Psr\Log\LoggerInterface
172188
*/
173189
public function logException(\Throwable $exception, array $context = []);
174190
}

0 commit comments

Comments
 (0)