Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Commit

Permalink
chore(travis): ignore 404 warnings, debug log into file
Browse files Browse the repository at this point in the history
This is a terrible hack/workaround, however I don't think there is any better way to achieve this
with log4js.
  • Loading branch information
vojtajina committed Dec 3, 2013
1 parent 5a8d9ac commit 09271a8
Showing 1 changed file with 40 additions and 2 deletions.
42 changes: 40 additions & 2 deletions karma-shared.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,52 @@ module.exports = function(config, specificOptions) {


if (process.env.TRAVIS) {
config.logLevel = config.LOG_DEBUG;
config.transports = ['websocket', 'xhr-polling'];
config.browserStack.build = 'TRAVIS ' + process.env.TRAVIS_BUILD_ID;

// Debug logging into a file, that we print out at the end of the build.
config.loggers.push({
type: 'file',
filename: process.env.LOGS_DIR + '/' + (specificOptions.logFile || 'karma.log'),
level: config.LOG_DEBUG
filename: process.env.LOGS_DIR + '/' + (specificOptions.logFile || 'karma.log')
});
}


// Terrible hack to workaround inflexibility of log4js:
// - ignore web-server's 404 warnings,
// - ignore DEBUG logs (on Travis), we log them into a file instead.
var IGNORED_404 = [
'/favicon.ico',
'/%7B%7BtestUrl%7D%7D',
'/someSanitizedUrl',
'/{{testUrl}}'
];
var log4js = require('./node_modules/karma/node_modules/log4js');
var layouts = require('./node_modules/karma/node_modules/log4js/lib/layouts');
var originalConfigure = log4js.configure;
log4js.configure = function(log4jsConfig) {
var consoleAppender = log4jsConfig.appenders.shift();
var originalResult = originalConfigure.call(log4js, log4jsConfig);
var layout = layouts.layout(consoleAppender.layout.type, consoleAppender.layout);



log4js.addAppender(function(log) {
// ignore web-server's 404s
if (log.categoryName === 'web-server' && log.level.levelStr === config.LOG_WARN &&
IGNORED_404.indexOf(log.data[0]) !== -1) {
return;
}

// on Travis, ignore DEBUG statements
if (process.env.TRAVIS && log.level.levelStr === config.LOG_DEBUG) {
return;
}

console.log(layout(log));
});

return originalResult;
};
};

0 comments on commit 09271a8

Please sign in to comment.