Translate extension for MediaWiki
 
Loading...
Searching...
No Matches
GenericTranslateJob.php
Go to the documentation of this file.
1<?php
10namespace MediaWiki\Extension\Translate\Jobs;
11
12use Job;
13use MediaWiki\Logger\LoggerFactory;
14use Psr\Log\LoggerInterface;
15
20abstract class GenericTranslateJob extends Job {
25 protected $logger;
26
31 private const CHANNEL_NAME = 'Translate.Jobs';
32
38 protected function getLogger() {
39 if ( $this->logger ) {
40 return $this->logger;
41 }
42
43 $this->logger = LoggerFactory::getInstance( self::CHANNEL_NAME );
44 return $this->logger;
45 }
46
47 protected function getLogPrefix(): string {
48 $prefix = $this->getType();
49 if ( isset( $this->title ) ) {
50 $prefix .= ' [' . $this->title->getPrefixedText() . ']';
51 }
52
53 // Add a separator at the end.
54 $prefix .= ': ';
55 return $prefix;
56 }
57
58 protected function logInfo( $msg, $context = [] ) {
59 $this->getLogger()->info( $this->getLogPrefix() . $msg, $context );
60 }
61
62 protected function logDebug( $msg, $context = [] ) {
63 $this->getLogger()->debug( $this->getLogPrefix() . $msg, $context );
64 }
65
66 protected function logError( $msg, $context = [] ) {
67 $this->getLogger()->error( $this->getLogPrefix() . $msg, $context );
68 }
69
70 protected function logWarning( $msg, $context = [] ) {
71 $this->getLogger()->warning( $this->getLogPrefix() . $msg, $context );
72 }
73}
getLogger()
Returns a logger instance with the channel name.