Skip to content
This repository has been archived by the owner on Jun 7, 2023. It is now read-only.

custom error logging on all skins #2873

Merged
merged 5 commits into from Mar 6, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
58 changes: 58 additions & 0 deletions extensions/wikia/Logger/WikiaLogger.class.php
Expand Up @@ -120,4 +120,62 @@ public function alert($message, $context=[]) {
public function emergency($message, $context=[]) {
return $this->logger->emergency($message, $context);
}

public static function onWikiaSkinTopScripts(&$vars, &$scripts) {
global $wgDevelEnvironment, $wgIsGASpecialWiki, $wgEnableJavaScriptErrorLogging, $wgCacheBuster, $wgMemc;

if (!$wgDevelEnvironment) {
$onError = $wgIsGASpecialWiki || $wgEnableJavaScriptErrorLogging;
$key = "wikialogger-top-script-$onError";
$loggingJs = $wgMemc->get($key);

if (!$loggingJs) {
$errorUrl = "//jserrorslog.wikia.com/";
$loggingJs = "
function syslogReport(priority, message, context) {
context = context || null;
var url = '$errorUrl',
i = new Image(),
data = {
'@message': message,
'syslog_pri': priority
};

if (context) {
data['@context'] = context;
}

try {
data['@fields'] = { server: document.cookie.match(/server.([A-Z]*).cache/)[1] };
} catch (e) {}

try {
i.src = url+'l?'+JSON.stringify(data);
} catch (e) {
i.src = url+'e?'+e;
}
}
";

if ($onError) {
$loggingJs .= "
window.onerror = function(m, u, l) {
if (Math.random() < 0.01) {
syslogReport(3, m, {'url': u, 'line': l}); // 3 is 'error'
}

return false;
}
";
}

$loggingJs = \AssetsManagerBaseBuilder::minifyJS($loggingJs);
$wgMemc->set($key, $loggingJs, 60*60*24);
}

$scripts = "<script>$loggingJs</script>$scripts";
}

return true;
}
}
2 changes: 2 additions & 0 deletions extensions/wikia/Logger/WikiaLogger.setup.php
Expand Up @@ -18,6 +18,8 @@
$wgAutoloadClasses['Wikia\\Logger\\WebProcessor'] = "{$dir}/WebProcessor.class.php";
$wgAutoloadClasses['Wikia\\Logger\\LogstashFormatter'] = "{$dir}/LogstashFormatter.class.php";

$wgHooks['WikiaSkinTopScripts'][] = 'Wikia\\Logger\\WikiaLogger::onWikiaSkinTopScripts';

$loggerClasses = [
'Psr' => [
'Log' => [
Expand Down
41 changes: 0 additions & 41 deletions skins/oasis/modules/templates/Oasis_Index.php
Expand Up @@ -33,47 +33,6 @@
<style type="text/css"><?= $pageCss ?></style>
<? endif ?>

<? // 1% of JavaScript errors are logged for $wgEnableJSerrorLogging=true non-devbox wikis
if (!$wg->DevelEnvironment):?>
<script>
function syslogReport(priority, message, context) {
context = context || null;
var url = "//jserrorslog.wikia.com/",
i = new Image(),
data = {
'@message': message,
'syslog_pri': priority
};

// url = '//jserrorslog.nelson.wikia-dev.com/';
if (context) {
data['@context'] = context;
}

try {
data['@fields'] = { server: document.cookie.match(/server.([A-Z]*).cache/)[1] };
} catch (e) {}

try {
i.src = url+'l?'+JSON.stringify(data);
} catch (e) {
i.src = url+'e?'+e;
}
}
</script><?
if ($wg->IsGASpecialWiki || $wg->EnableJavaScriptErrorLogging):?>
<script>
window.onerror = function(m,u,l) {
if (Math.random() < 0.01) {
syslogReport(3, m, {'url': u, 'line': l}); // 3 is "error"
}

return false;
}
</script>
<? endif ?>
<? endif ?>

<?= $topScripts ?>
<?= $wikiaScriptLoader; /*needed for jsLoader and for the async loading of CSS files.*/ ?>

Expand Down