Translate extension for MediaWiki
 
Loading...
Searching...
No Matches
GenericTranslateJob.php
1<?php
2declare( strict_types = 1 );
3
4namespace MediaWiki\Extension\Translate\Jobs;
5
6use Job;
8use MediaWiki\Logger\LoggerFactory;
9use Psr\Log\LoggerInterface;
10
17abstract class GenericTranslateJob extends Job {
18 private LoggerInterface $logger;
19
24 private function getLogger(): LoggerInterface {
25 $this->logger ??= LoggerFactory::getInstance( LogNames::JOBS );
26 return $this->logger;
27 }
28
30 private function formatLogEntry( string $msg, array $context = [] ): array {
31 $prefix = $this->getType();
32 if ( isset( $this->title ) ) {
33 $prefix .= ' [{job_title}]';
34 $context['job_title'] = $this->title->getPrefixedText();
35 }
36
37 return [ "$prefix: $msg", $context ];
38 }
39
40 protected function logDebug( string $msg, array $context = [] ): void {
41 [ $msg, $context ] = $this->formatLogEntry( $msg, $context );
42 $this->getLogger()->debug( $msg, $context );
43 }
44
45 protected function logInfo( string $msg, array $context = [] ): void {
46 [ $msg, $context ] = $this->formatLogEntry( $msg, $context );
47 $this->getLogger()->info( $msg, $context );
48 }
49
50 protected function logNotice( string $msg, array $context = [] ): void {
51 [ $msg, $context ] = $this->formatLogEntry( $msg, $context );
52 $this->getLogger()->notice( $msg, $context );
53 }
54
55 protected function logWarning( string $msg, array $context = [] ): void {
56 [ $msg, $context ] = $this->formatLogEntry( $msg, $context );
57 $this->getLogger()->warning( $msg, $context );
58 }
59
60 protected function logError( string $msg, array $context = [] ): void {
61 [ $msg, $context ] = $this->formatLogEntry( $msg, $context );
62 $this->getLogger()->error( $msg, $context );
63 }
64}
Constants for log channel names used in this extension.
Definition LogNames.php:13