Skip to content

Commit

Permalink
feat(logging): Add colors and log-level options to run-command
Browse files Browse the repository at this point in the history
 Add colors and log-level arguments to run argument.
 Refactor log-setup functions for server and init.
 Correct bug in server where log-level was ignored before `parseConfig`

Closing karma-runner#1067
  • Loading branch information
budde377 committed Feb 22, 2016
1 parent 6fe5a77 commit 411970a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 18 deletions.
3 changes: 3 additions & 0 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ var describeRun = function () {
.describe('fail-on-empty-test-suite', 'Fail on empty test suite.')
.describe('no-fail-on-empty-test-suite', 'Do not fail on empty test suite.')
.describe('help', 'Print usage.')
.describe('log-level', '<disable | error | warn | info | debug> Level of logging.')
.describe('colors', 'Use colors when reporting and printing logs.')
.describe('no-colors', 'Do not use colors when reporting or printing logs.')
}

var describeStop = function () {
Expand Down
13 changes: 2 additions & 11 deletions lib/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ var exec = require('child_process').exec

var helper = require('./helper')
var logger = require('./logger')
var constant = require('./constants')

var log = logger.create('init')

Expand Down Expand Up @@ -211,21 +210,13 @@ var processAnswers = function (answers, basePath, testMainFile) {
}

exports.init = function (config) {
var useColors = true
var logLevel = constant.LOG_INFO
logger.setupFromConfig(config)

var colorScheme = COLOR_SCHEME.ON

if (helper.isDefined(config.colors)) {
colorScheme = config.colors ? COLOR_SCHEME.ON : COLOR_SCHEME.OFF
useColors = config.colors
}

if (helper.isDefined(config.logLevel)) {
logLevel = config.logLevel
}

logger.setup(logLevel, useColors)

// need to be registered before creating readlineInterface
process.stdin.on('keypress', function (s, key) {
sm.onKeypress(key)
Expand Down
8 changes: 1 addition & 7 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,11 @@ function createSocketIoServer (webServer, executor, config) {
return server
}

function setupLogger (level, colors) {
var logLevel = logLevel || constant.LOG_INFO
var logColors = helper.isDefined(colors) ? colors : true
logger.setup(logLevel, logColors, [constant.CONSOLE_APPENDER])
}

// Constructor
var Server = function (cliOptions, done) {
EventEmitter.call(this)

setupLogger(cliOptions.logLevel, cliOptions.colors)
logger.setupFromConfig(cliOptions)

this.log = logger.create()

Expand Down

0 comments on commit 411970a

Please sign in to comment.