From 09271a8ab945df19ec3aacf43f60c458fafd82fd Mon Sep 17 00:00:00 2001 From: Vojta Jina Date: Mon, 2 Dec 2013 13:51:09 -0800 Subject: chore(travis): ignore 404 warnings, debug log into file This is a terrible hack/workaround, however I don't think there is any better way to achieve this with log4js. --- karma-shared.conf.js | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) (limited to 'karma-shared.conf.js') diff --git a/karma-shared.conf.js b/karma-shared.conf.js index 3659e582..ac8e4f91 100644 --- a/karma-shared.conf.js +++ b/karma-shared.conf.js @@ -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; + }; }; -- cgit v1.2.3