Karma: browserConsoleLogOptions does not filter console by level

Created on 2 Jul 2016  路  5Comments  路  Source: karma-runner/karma

Expected behavior

I expect that if browserConsoleLogOptions.level === 'error', then any instance of console.log, console.debug or console.warn will not appear in my terminal.

Actual behavior

Instances of console.debug are still shown in my console, despite the following in my Karma configuration:

    browserConsoleLogOptions: {
      level: 'error',
      format: '%b %T: %m',
      terminal: true
    },

Specifically, console.debug('hello there!'); results in DEBUG: 'hello there!' being printed when I run tests.

Note that switching browserConsoleLogOptions.terminal to false correctly silences all console output.

Enviroment Details

Karma 1.1.0 with Webpack 2 through Babel 6 on macOS 10.11.5 with npm 3.8.8 and node v5.11.0. Please see package.json for full requirements.

Steps to reproduce the behaviour

  1. Clone the example repo found at https://github.com/jambonsw/webpack2-karma-logging-error-mve
  2. Install the packages with npm install
  3. Run tests with npm test
help wanted bug

Most helpful comment

It seems that browserConsoleLogOptions.level is only taken into account for log files. There's no filter for reporters.
I'd like to help out with this one.

Also, I noticed that the current log levels are: ['log', 'error', 'warn', 'info', 'debug']
Since log has an higher level than error, console.log messages are always printed also if browserConsoleLogOptions.level is set to 'error'.
@dignifiedquire is this a wanted behaviour?

All 5 comments

It seems that browserConsoleLogOptions.level is only taken into account for log files. There's no filter for reporters.
I'd like to help out with this one.

Also, I noticed that the current log levels are: ['log', 'error', 'warn', 'info', 'debug']
Since log has an higher level than error, console.log messages are always printed also if browserConsoleLogOptions.level is set to 'error'.
@dignifiedquire is this a wanted behaviour?

@dignifiedquire if you describe the correct behaviour i can take over this bugfix and propose a pr with possible solution

@vigreco yes we should keep this. The reasoning being that you usually use console.log for debugging, while still wanting to keep only errors otherwise.

This should be changed to what was described in the original report. Moving log down between warn and info.

can you merge it?
Also I think you missed to add the 'LOG' level itself to constants.js,
it should be:

exports.LOG_LOG = 'LOG'

exports.LOG_PRIORITIES = [
exports.LOG_DISABLE,
exports.LOG_ERROR,
exports.LOG_WARN,
exports.LOG_INFO,
exports.LOG_DEBUG,
exports.LOG_DISABLE,
exports.LOG_LOG
]

This change made the LOG level messages the lowest priority, which I think should not be the case based on the comment by @dignifiedquire above:

This should be changed to what was described in the original report. Moving log down between warn and info.

See #2602.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

charpour picture charpour  路  3Comments

jhildenbiddle picture jhildenbiddle  路  4Comments

macjohnny picture macjohnny  路  5Comments

anius picture anius  路  3Comments

mboughaba picture mboughaba  路  3Comments