Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 8 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
GenericTranslationNotificationsJob | |
0.00% |
0 / 8 |
|
0.00% |
0 / 6 |
42 | |
0.00% |
0 / 1 |
run | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
getLogger | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
getLogPrefix | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
logInfo | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
logDebug | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
logError | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
logWarn | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | declare( strict_types = 1 ); |
3 | |
4 | namespace MediaWiki\Extension\TranslationNotifications\Jobs; |
5 | |
6 | use Job; |
7 | use MediaWiki\Logger\LoggerFactory; |
8 | use Psr\Log\LoggerInterface; |
9 | |
10 | /** |
11 | * Generic Job class extended by other jobs. Provides logging functionality. |
12 | * @author Abijeet Patro |
13 | * @license GPL-2.0-or-later |
14 | */ |
15 | abstract class GenericTranslationNotificationsJob extends Job { |
16 | protected LoggerInterface $logger; |
17 | |
18 | /** |
19 | * Channel name to be used during logging |
20 | * @var string |
21 | */ |
22 | private const CHANNEL_NAME = 'TranslationNotifications.Jobs'; |
23 | |
24 | abstract public function run(); |
25 | |
26 | /** |
27 | * Returns a logger instance with the channel name. Can have only a single |
28 | * channel per job, so once instantiated, the same instance is returned. |
29 | */ |
30 | protected function getLogger(): LoggerInterface { |
31 | $this->logger ??= LoggerFactory::getInstance( self::CHANNEL_NAME ); |
32 | return $this->logger; |
33 | } |
34 | |
35 | protected function getLogPrefix(): string { |
36 | return '[Job: ' . $this->getType() . '][Request ID: ' . $this->getRequestId() . |
37 | '][Title: ' . $this->title->getPrefixedText() . '] '; |
38 | } |
39 | |
40 | protected function logInfo( string $msg, array $context = [] ): void { |
41 | $this->getLogger()->info( $this->getLogPrefix() . $msg, $context ); |
42 | } |
43 | |
44 | protected function logDebug( string $msg, array $context = [] ): void { |
45 | $this->getLogger()->debug( $this->getLogPrefix() . $msg, $context ); |
46 | } |
47 | |
48 | protected function logError( string $msg, array $context = [] ): void { |
49 | $this->getLogger()->error( $this->getLogPrefix() . $msg, $context ); |
50 | } |
51 | |
52 | protected function logWarn( string $msg, array $context = [] ): void { |
53 | $this->getLogger()->warning( $this->getLogPrefix() . $msg, $context ); |
54 | } |
55 | } |