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;
7use MediaWiki\Logger\LoggerFactory;
8use Psr\Log\LoggerInterface;
9
16abstract class GenericTranslateJob extends Job {
17 private LoggerInterface $logger;
18
20 private const CHANNEL_NAME = 'Translate.Jobs';
21
26 private function getLogger(): LoggerInterface {
27 $this->logger ??= LoggerFactory::getInstance( self::CHANNEL_NAME );
28 return $this->logger;
29 }
30
32 private function formatLogEntry( string $msg, array $context = [] ): array {
33 $prefix = $this->getType();
34 if ( isset( $this->title ) ) {
35 $prefix .= ' [{job_title}]';
36 $context['job_title'] = $this->title->getPrefixedText();
37 }
38
39 return [ "$prefix: $msg", $context ];
40 }
41
42 protected function logDebug( string $msg, array $context = [] ): void {
43 [ $msg, $context ] = $this->formatLogEntry( $msg, $context );
44 $this->getLogger()->debug( $msg, $context );
45 }
46
47 protected function logInfo( string $msg, array $context = [] ): void {
48 [ $msg, $context ] = $this->formatLogEntry( $msg, $context );
49 $this->getLogger()->info( $msg, $context );
50 }
51
52 protected function logNotice( string $msg, array $context = [] ): void {
53 [ $msg, $context ] = $this->formatLogEntry( $msg, $context );
54 $this->getLogger()->notice( $msg, $context );
55 }
56
57 protected function logWarning( string $msg, array $context = [] ): void {
58 [ $msg, $context ] = $this->formatLogEntry( $msg, $context );
59 $this->getLogger()->warning( $msg, $context );
60 }
61
62 protected function logError( string $msg, array $context = [] ): void {
63 [ $msg, $context ] = $this->formatLogEntry( $msg, $context );
64 $this->getLogger()->error( $msg, $context );
65 }
66}