Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

browserConsoleLogOptions does not filter console by level #2228

Closed
jambonrose opened this issue Jul 1, 2016 · 5 comments · Fixed by #2540 or karronoli/redpen#10 · May be fixed by Omrisnyk/npm-lockfiles#122 or Omrisnyk/npm-lockfiles#132
Closed

Comments

@jambonrose
Copy link

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
@vigreco
Copy link

vigreco commented Aug 19, 2016

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?

@romulocintra
Copy link

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

@dignifiedquire
Copy link
Member

dignifiedquire commented Dec 7, 2016

@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.

@blackswanny
Copy link
Contributor

blackswanny commented Jan 12, 2017

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
]

blackswanny added a commit to blackswanny/karma that referenced this issue Jan 17, 2017
Additional fix to the next bug:
filter browser logging by level  ([35965d9](karma-runner@35965d9)), closes [karma-runner#2228](karma-runner#2228)
otherwise console.log ignore doesn't work with 
    browserConsoleLogOptions: {
        level: 'debug',
        terminal: true
    }
dignifiedquire pushed a commit that referenced this issue Feb 19, 2017
Additional fix to the bug, "filter browser logging by level" ([35965d9](35965d9)), closes [#2228](#2228)

Otherwise console.log ignore doesn't work with 
```
browserConsoleLogOptions: {
  level: 'debug',
  terminal: true
}
```
@IgorAufricht
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment