function logToFile($msg, $file) { $header = '[' . date('d\\TH:i:s') . '] ' . wfHostname() . ' ' . posix_getpid(); if ($this->slaveId !== false) { $header .= "({$this->slaveId})"; } $header .= ' ' . wfWikiID(); LegacyLogger::emit(sprintf("%-50s %s\n", $header, $msg), $file); }
public function format(array $record) { $normalized = parent::format($record); return LegacyLogger::format($normalized['channel'], $normalized['message'], $normalized); }
} // Process data & print results if ($processor) { $processor->execute(); } // Log what the user did, for book-keeping purposes. $endtime = microtime(true); // Log the request if ($wgAPIRequestLog) { $items = array(wfTimestamp(TS_MW), $endtime - $starttime, $wgRequest->getIP(), $wgRequest->getHeader('User-agent')); $items[] = $wgRequest->wasPosted() ? 'POST' : 'GET'; if ($processor) { try { $manager = $processor->getModuleManager(); $module = $manager->getModule($wgRequest->getVal('action'), 'action'); } catch (Exception $ex) { $module = null; } if (!$module || $module->mustBePosted()) { $items[] = "action=" . $wgRequest->getVal('action'); } else { $items[] = wfArrayToCgi($wgRequest->getValues()); } } else { $items[] = "failed in ApiBeforeMain"; } LegacyLogger::emit(implode(',', $items) . "\n", $wgAPIRequestLog); wfDebug("Logged API request to {$wgAPIRequestLog}\n"); } $mediawiki = new MediaWiki(); $mediawiki->doPostOutputShutdown('fast');
/** * @covers LegacyLogger::shouldEmit * @dataProvider provideShouldEmit */ public function testShouldEmit($level, $config, $expected) { $this->setMwGlobals('wgDebugLogGroups', array('fakechannel' => $config)); $this->assertEquals($expected, LegacyLogger::shouldEmit('fakechannel', 'some message', $level, array())); }
protected function write(array $record) { if ($this->useLegacyFilter && !LegacyLogger::shouldEmit($record['channel'], $record['message'], $record['level'], $record)) { // Do not write record if we are enforcing legacy rules and they // do not pass this message. This used to be done in isHandling(), // but Monolog 1.12.0 made a breaking change that removed access // to the needed channel and context information. return; } if ($this->sink === null) { $this->openSink(); } $text = (string) $record['formatted']; if ($this->useUdp()) { // Clean it up for the multiplexer if ($this->prefix !== '') { $leader = $this->prefix === '{channel}' ? $record['channel'] : $this->prefix; $text = preg_replace('/^/m', "{$leader} ", $text); // Limit to 64KB if (strlen($text) > 65506) { $text = substr($text, 0, 65506); } if (substr($text, -1) != "\n") { $text .= "\n"; } } elseif (strlen($text) > 65507) { $text = substr($text, 0, 65507); } socket_sendto($this->sink, $text, strlen($text), 0, $this->host, $this->port); } else { fwrite($this->sink, $text); } }
/** * This is a method to pass messages from wfDebug to the pretty debugger. * Do NOT use this method, use MWDebug::log or wfDebug() * * @since 1.19 * @param string $str * @param array $context */ public static function debugMsg($str, $context = []) { global $wgDebugComments, $wgShowDebug; if (self::$enabled || $wgDebugComments || $wgShowDebug) { if ($context) { $prefix = ''; if (isset($context['prefix'])) { $prefix = $context['prefix']; } elseif (isset($context['channel']) && $context['channel'] !== 'wfDebug') { $prefix = "[{$context['channel']}] "; } if (isset($context['seconds_elapsed']) && isset($context['memory_used'])) { $prefix .= "{$context['seconds_elapsed']} {$context['memory_used']} "; } $str = LegacyLogger::interpolate($str, $context); $str = $prefix . $str; } self::$debug[] = rtrim(UtfNormal\Validator::cleanUp($str)); } }