本文整理汇总了PHP中MediaWiki\Logger\LoggerFactory类的典型用法代码示例。如果您正苦于以下问题:PHP LoggerFactory类的具体用法?PHP LoggerFactory怎么用?PHP LoggerFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了LoggerFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: applyDefaultParameters
/**
* @param array $params
* @param Config $mainConfig
* @return array
*/
public static function applyDefaultParameters(array $params, Config $mainConfig)
{
$logger = LoggerFactory::getInstance('Mime');
$params += ['typeFile' => $mainConfig->get('MimeTypeFile'), 'infoFile' => $mainConfig->get('MimeInfoFile'), 'xmlTypes' => $mainConfig->get('XMLMimeTypes'), 'guessCallback' => function ($mimeAnalyzer, &$head, &$tail, $file, &$mime) use($logger) {
// Also test DjVu
$deja = new DjVuImage($file);
if ($deja->isValid()) {
$logger->info(__METHOD__ . ": detected {$file} as image/vnd.djvu\n");
$mime = 'image/vnd.djvu';
return;
}
// Some strings by reference for performance - assuming well-behaved hooks
Hooks::run('MimeMagicGuessFromContent', [$mimeAnalyzer, &$head, &$tail, $file, &$mime]);
}, 'extCallback' => function ($mimeAnalyzer, $ext, &$mime) {
// Media handling extensions can improve the MIME detected
Hooks::run('MimeMagicImproveFromExtension', [$mimeAnalyzer, $ext, &$mime]);
}, 'initCallback' => function ($mimeAnalyzer) {
// Allow media handling extensions adding MIME-types and MIME-info
Hooks::run('MimeMagicInit', [$mimeAnalyzer]);
}, 'logger' => $logger];
if ($params['infoFile'] === 'includes/mime.info') {
$params['infoFile'] = __DIR__ . "/libs/mime/mime.info";
}
if ($params['typeFile'] === 'includes/mime.types') {
$params['typeFile'] = __DIR__ . "/libs/mime/mime.types";
}
$detectorCmd = $mainConfig->get('MimeDetectorCommand');
if ($detectorCmd) {
$params['detectCallback'] = function ($file) use($detectorCmd) {
return wfShellExec("{$detectorCmd} " . wfEscapeShellArg($file));
};
}
return $params;
}
示例2: execute
public function execute()
{
global $wgCommandLineMode;
if ($this->hasOption('procs')) {
$procs = intval($this->getOption('procs'));
if ($procs < 1 || $procs > 1000) {
$this->error("Invalid argument to --procs", true);
} elseif ($procs != 1) {
$fc = new ForkController($procs);
if ($fc->start() != 'child') {
exit(0);
}
}
}
$outputJSON = $this->getOption('result') === 'json';
// Enable DBO_TRX for atomicity; JobRunner manages transactions
// and works well in web server mode already (@TODO: this is a hack)
$wgCommandLineMode = false;
$runner = new JobRunner(LoggerFactory::getInstance('runJobs'));
if (!$outputJSON) {
$runner->setDebugHandler(array($this, 'debugInternal'));
}
$response = $runner->run(array('type' => $this->getOption('type', false), 'maxJobs' => $this->getOption('maxjobs', false), 'maxTime' => $this->getOption('maxtime', false), 'throttle' => $this->hasOption('nothrottle') ? false : true));
if ($outputJSON) {
$this->output(FormatJson::encode($response, true));
}
$wgCommandLineMode = true;
}
示例3: __construct
/**
* @param LoggerInterface $logger
*/
public function __construct(LoggerInterface $logger = null)
{
if ($logger === null) {
$logger = LoggerFactory::getInstance('runJobs');
}
$this->setLogger($logger);
}
示例4: getMonthViews
protected static function getMonthViews(Title $title)
{
global $wgMemc;
$key = wfMemcKey('pvi', 'month', md5($title->getPrefixedText()));
$data = $wgMemc->get($key);
if ($data) {
return $data;
}
$today = date('Ymd');
$lastMonth = date('Ymd', time() - 60 * 60 * 24 * 30);
$url = self::buildApiUrl($title, $lastMonth, $today);
$req = MWHttpRequest::factory($url, ['timeout' => 10], __METHOD__);
$status = $req->execute();
if (!$status->isOK()) {
LoggerFactory::getInstance('PageViewInfo')->error("Failed fetching {$url}: {$status->getWikiText()}", ['url' => $url, 'title' => $title->getPrefixedText()]);
return false;
}
$data = FormatJson::decode($req->getContent(), true);
// Add our start/end periods
$data['start'] = $lastMonth;
$data['end'] = $today;
// Cache for an hour
$wgMemc->set($key, $data, 60 * 60);
return $data;
}
示例5: execute
public function execute()
{
if (wfReadOnly()) {
$this->error("Unable to run jobs; the wiki is in read-only mode.", 1);
// die
}
if ($this->hasOption('procs')) {
$procs = intval($this->getOption('procs'));
if ($procs < 1 || $procs > 1000) {
$this->error("Invalid argument to --procs", true);
} elseif ($procs != 1) {
$fc = new ForkController($procs);
if ($fc->start() != 'child') {
exit(0);
}
}
}
$json = $this->getOption('result') === 'json';
$runner = new JobRunner(LoggerFactory::getInstance('runJobs'));
if (!$json) {
$runner->setDebugHandler(array($this, 'debugInternal'));
}
$response = $runner->run(array('type' => $this->getOption('type', false), 'maxJobs' => $this->getOption('maxjobs', false), 'maxTime' => $this->getOption('maxtime', false), 'throttle' => $this->hasOption('nothrottle') ? false : true));
if ($json) {
$this->output(FormatJson::encode($response, true));
}
}
示例6: __construct
/**
* @param array $params Possible keys:
* - redisConfig : An array of parameters to RedisConnectionPool::__construct().
* - redisServers : Array of server entries, the first being the primary and the
* others being fallback servers. Each entry is either a hostname/port
* combination or the absolute path of a UNIX socket.
* If a hostname is specified but no port, the standard port number
* 6379 will be used. Required.
*/
public function __construct(array $params)
{
parent::__construct($params);
$this->servers = isset($params['redisServers']) ? $params['redisServers'] : [$params['redisServer']];
// b/c
$params['redisConfig']['serializer'] = 'none';
$this->redisPool = RedisConnectionPool::singleton($params['redisConfig']);
$this->logger = \MediaWiki\Logger\LoggerFactory::getInstance('redis');
}
示例7: __construct
/**
* Construct a factory based on a configuration array (typically from $wgLBFactoryConf)
* @param array $conf
*/
public function __construct(array $conf)
{
if (isset($conf['readOnlyReason']) && is_string($conf['readOnlyReason'])) {
$this->readOnlyReason = $conf['readOnlyReason'];
}
$this->chronProt = $this->newChronologyProtector();
$this->trxProfiler = Profiler::instance()->getTransactionProfiler();
$this->logger = LoggerFactory::getInstance('DBTransaction');
}
示例8: execute
public function execute($par = '')
{
$this->getOutput()->disable();
if (wfReadOnly()) {
// HTTP 423 Locked
HttpStatus::header(423);
print 'Wiki is in read-only mode';
return;
} elseif (!$this->getRequest()->wasPosted()) {
HttpStatus::header(400);
print 'Request must be POSTed';
return;
}
$optional = array('maxjobs' => 0, 'maxtime' => 30, 'type' => false, 'async' => true);
$required = array_flip(array('title', 'tasks', 'signature', 'sigexpiry'));
$params = array_intersect_key($this->getRequest()->getValues(), $required + $optional);
$missing = array_diff_key($required, $params);
if (count($missing)) {
HttpStatus::header(400);
print 'Missing parameters: ' . implode(', ', array_keys($missing));
return;
}
$squery = $params;
unset($squery['signature']);
$correctSignature = self::getQuerySignature($squery, $this->getConfig()->get('SecretKey'));
$providedSignature = $params['signature'];
$verified = is_string($providedSignature) && hash_equals($correctSignature, $providedSignature);
if (!$verified || $params['sigexpiry'] < time()) {
HttpStatus::header(400);
print 'Invalid or stale signature provided';
return;
}
// Apply any default parameter values
$params += $optional;
if ($params['async']) {
// Client will usually disconnect before checking the response,
// but it needs to know when it is safe to disconnect. Until this
// reaches ignore_user_abort(), it is not safe as the jobs won't run.
ignore_user_abort(true);
// jobs may take a bit of time
// HTTP 202 Accepted
HttpStatus::header(202);
ob_flush();
flush();
// Once the client receives this response, it can disconnect
}
// Do all of the specified tasks...
if (in_array('jobs', explode('|', $params['tasks']))) {
$runner = new JobRunner(LoggerFactory::getInstance('runJobs'));
$response = $runner->run(array('type' => $params['type'], 'maxJobs' => $params['maxjobs'] ? $params['maxjobs'] : 1, 'maxTime' => $params['maxtime'] ? $params['maxjobs'] : 30));
if (!$params['async']) {
print FormatJson::encode($response, true);
}
}
}
示例9: applyDefaultConfig
/**
* @param array $lbConf Config for LBFactory::__construct()
* @param Config $mainConfig Main config object from MediaWikiServices
* @return array
*/
public static function applyDefaultConfig(array $lbConf, Config $mainConfig)
{
global $wgCommandLineMode;
$lbConf += ['localDomain' => new DatabaseDomain($mainConfig->get('DBname'), null, $mainConfig->get('DBprefix')), 'profiler' => Profiler::instance(), 'trxProfiler' => Profiler::instance()->getTransactionProfiler(), 'replLogger' => LoggerFactory::getInstance('DBReplication'), 'queryLogger' => LoggerFactory::getInstance('DBQuery'), 'connLogger' => LoggerFactory::getInstance('DBConnection'), 'perfLogger' => LoggerFactory::getInstance('DBPerformance'), 'errorLogger' => [MWExceptionHandler::class, 'logException'], 'cliMode' => $wgCommandLineMode, 'hostname' => wfHostname(), 'readOnlyReason' => wfConfiguredReadOnlyReason()];
if ($lbConf['class'] === 'LBFactorySimple') {
if (isset($lbConf['servers'])) {
// Server array is already explicitly configured; leave alone
} elseif (is_array($mainConfig->get('DBservers'))) {
foreach ($mainConfig->get('DBservers') as $i => $server) {
if ($server['type'] === 'sqlite') {
$server += ['dbDirectory' => $mainConfig->get('SQLiteDataDir')];
} elseif ($server['type'] === 'postgres') {
$server += ['port' => $mainConfig->get('DBport')];
}
$lbConf['servers'][$i] = $server + ['schema' => $mainConfig->get('DBmwschema'), 'tablePrefix' => $mainConfig->get('DBprefix'), 'flags' => DBO_DEFAULT, 'sqlMode' => $mainConfig->get('SQLMode'), 'utf8Mode' => $mainConfig->get('DBmysql5')];
}
} else {
$flags = DBO_DEFAULT;
$flags |= $mainConfig->get('DebugDumpSql') ? DBO_DEBUG : 0;
$flags |= $mainConfig->get('DBssl') ? DBO_SSL : 0;
$flags |= $mainConfig->get('DBcompress') ? DBO_COMPRESS : 0;
$server = ['host' => $mainConfig->get('DBserver'), 'user' => $mainConfig->get('DBuser'), 'password' => $mainConfig->get('DBpassword'), 'dbname' => $mainConfig->get('DBname'), 'schema' => $mainConfig->get('DBmwschema'), 'tablePrefix' => $mainConfig->get('DBprefix'), 'type' => $mainConfig->get('DBtype'), 'load' => 1, 'flags' => $flags, 'sqlMode' => $mainConfig->get('SQLMode'), 'utf8Mode' => $mainConfig->get('DBmysql5')];
if ($server['type'] === 'sqlite') {
$server['dbDirectory'] = $mainConfig->get('SQLiteDataDir');
} elseif ($server['type'] === 'postgres') {
$server['port'] = $mainConfig->get('DBport');
}
$lbConf['servers'] = [$server];
}
if (!isset($lbConf['externalClusters'])) {
$lbConf['externalClusters'] = $mainConfig->get('ExternalServers');
}
} elseif ($lbConf['class'] === 'LBFactoryMulti') {
if (isset($lbConf['serverTemplate'])) {
$lbConf['serverTemplate']['schema'] = $mainConfig->get('DBmwschema');
$lbConf['serverTemplate']['sqlMode'] = $mainConfig->get('SQLMode');
$lbConf['serverTemplate']['utf8Mode'] = $mainConfig->get('DBmysql5');
}
}
// Use APC/memcached style caching, but avoids loops with CACHE_DB (T141804)
$sCache = MediaWikiServices::getInstance()->getLocalServerObjectCache();
if ($sCache->getQoS($sCache::ATTR_EMULATION) > $sCache::QOS_EMULATION_SQL) {
$lbConf['srvCache'] = $sCache;
}
$cCache = ObjectCache::getLocalClusterInstance();
if ($cCache->getQoS($cCache::ATTR_EMULATION) > $cCache::QOS_EMULATION_SQL) {
$lbConf['memCache'] = $cCache;
}
$wCache = MediaWikiServices::getInstance()->getMainWANObjectCache();
if ($wCache->getQoS($wCache::ATTR_EMULATION) > $wCache::QOS_EMULATION_SQL) {
$lbConf['wanCache'] = $wCache;
}
return $lbConf;
}
示例10: execute
/**
* Logs a content-security-policy violation report from web browser.
*/
public function execute()
{
$reportOnly = $this->getParameter('reportonly');
$logname = $reportOnly ? 'csp-report-only' : 'csp';
$this->log = LoggerFactory::getInstance($logname);
$userAgent = $this->getRequest()->getHeader('user-agent');
$this->verifyPostBodyOk();
$report = $this->getReport();
$flags = $this->getFlags($report);
$warningText = $this->generateLogLine($flags, $report);
$this->logReport($flags, $warningText, ['csp-report' => $report, 'method' => __METHOD__, 'user' => $this->getUser()->getName(), 'user-agent' => $userAgent, 'source' => $this->getParameter('source')]);
$this->getResult()->addValue(null, $this->getModuleName(), 'success');
}
示例11: doLog
private function doLog()
{
$logger = LoggerFactory::getInstance('HttpError');
$content = $this->content;
if ($content instanceof Message) {
$content = $content->text();
}
$context = ['file' => $this->getFile(), 'line' => $this->getLine(), 'http_code' => $this->httpCode];
$logMsg = "{$content} ({http_code}) from {file}:{line}";
if ($this->getStatusCode() < 500) {
$logger->info($logMsg, $context);
} else {
$logger->error($logMsg, $context);
}
}
示例12: doJob
protected function doJob()
{
// Reload pages from pageIds to throw into the updater
$pageData = array();
foreach ($this->params['pageDBKeys'] as $pageDBKey) {
$title = Title::newFromDBKey($pageDBKey);
// Skip any titles with broken keys. We can't do anything with them.
if (!$title) {
LoggerFactory::getInstance('CirrusSearch')->warning("Skipping invalid DBKey: {pageDBKey}", array('pageDBKey' => $pageDBKey));
continue;
}
$pageData[] = WikiPage::factory($title);
}
// Now invoke the updater!
$updater = $this->createUpdater();
$count = $updater->updatePages($pageData, null, null, $this->params['updateFlags']);
return $count >= 0;
}
示例13: __construct
/**
* @param array $conditions An array of arrays describing throttling conditions.
* Defaults to $wgPasswordAttemptThrottle. See documentation of that variable for format.
* @param array $params Parameters (all optional):
* - type: throttle type, used as a namespace for counters,
* - cache: a BagOStuff object where throttle counters are stored.
* - warningLimit: the log level will be raised to warning when rejecting an attempt after
* no less than this many failures.
*/
public function __construct(array $conditions = null, array $params = [])
{
$invalidParams = array_diff_key($params, array_fill_keys(['type', 'cache', 'warningLimit'], true));
if ($invalidParams) {
throw new \InvalidArgumentException('unrecognized parameters: ' . implode(', ', array_keys($invalidParams)));
}
if ($conditions === null) {
$config = \ConfigFactory::getDefaultInstance()->makeConfig('main');
$conditions = $config->get('PasswordAttemptThrottle');
$params += ['type' => 'password', 'cache' => \ObjectCache::getLocalClusterInstance(), 'warningLimit' => 50];
} else {
$params += ['type' => 'custom', 'cache' => \ObjectCache::getLocalClusterInstance(), 'warningLimit' => INF];
}
$this->type = $params['type'];
$this->conditions = static::normalizeThrottleConditions($conditions);
$this->cache = $params['cache'];
$this->warningLimit = $params['warningLimit'];
$this->setLogger(LoggerFactory::getInstance('throttler'));
}
示例14: pickBest
/**
* Pick the best near match if possible.
*
* @return Title|null title if there is a near match and null otherwise
*/
public function pickBest()
{
if (!$this->titles) {
return null;
}
if (!$this->term) {
return null;
}
if (count($this->titles) === 1) {
if (isset($this->titles[0]['titleMatch'])) {
return $this->titles[0]['titleMatch'];
}
if (isset($this->titles[0]['redirectMatches'][0])) {
return $this->titles[0]['redirectMatches'][0];
}
LoggerFactory::getInstance('CirrusSearch')->info('NearMatchPicker built with busted matches. Assuming no near match');
return null;
}
$transformers = array(function ($term) {
return $term;
}, array($this->language, 'lc'), array($this->language, 'ucwords'));
foreach ($transformers as $transformer) {
$transformedTerm = call_user_func($transformer, $this->term);
$found = null;
foreach ($this->titles as $title) {
$match = $this->checkAllMatches($transformer, $transformedTerm, $title);
if ($match) {
if (!$found) {
$found = $match;
} else {
// Found more than one result so we try another transformer
$found = null;
break;
}
}
}
if ($found) {
return $found;
}
}
// Didn't find anything
return null;
}
示例15: execute
public function execute()
{
global $wgCommandLineMode;
if ($this->hasOption('procs')) {
$procs = intval($this->getOption('procs'));
if ($procs < 1 || $procs > 1000) {
$this->error("Invalid argument to --procs", true);
} elseif ($procs != 1) {
$fc = new ForkController($procs);
if ($fc->start() != 'child') {
exit(0);
}
}
}
$outputJSON = $this->getOption('result') === 'json';
$wait = $this->hasOption('wait');
// Enable DBO_TRX for atomicity; JobRunner manages transactions
// and works well in web server mode already (@TODO: this is a hack)
$wgCommandLineMode = false;
$runner = new JobRunner(LoggerFactory::getInstance('runJobs'));
if (!$outputJSON) {
$runner->setDebugHandler([$this, 'debugInternal']);
}
$type = $this->getOption('type', false);
$maxJobs = $this->getOption('maxjobs', false);
$maxTime = $this->getOption('maxtime', false);
$throttle = !$this->hasOption('nothrottle');
while (true) {
$response = $runner->run(['type' => $type, 'maxJobs' => $maxJobs, 'maxTime' => $maxTime, 'throttle' => $throttle]);
if ($outputJSON) {
$this->output(FormatJson::encode($response, true));
}
if (!$wait || $response['reached'] === 'time-limit' || $response['reached'] === 'job-limit' || $response['reached'] === 'memory-limit') {
break;
}
if ($maxJobs !== false) {
$maxJobs -= count($response['jobs']);
}
sleep(1);
}
$wgCommandLineMode = true;
}