The level of logging by karma can be changed in the karma.conf.js file.
Go to karma.conf.js and add/change the property logLevel to config.LOG_DISABLE if you don't want to see any logs or config.LOG_ERROR if you want to only see the errors. Like this:
module.exports = function (config) {
config.set({
...,
logLevel: config.LOG_ERROR,
...,
})
}
If you are running karma from the command line you can append --log-level debug to the command for the same effect.
angular - Debug Tests in NG Test - Stack Overflow
ng test logging
angularjs - is it possible in angular to set the debug log level at runtime? - Stack Overflow
Angular CLI is up and running event ng test --watch false after finishing
» npm install @ng-lv/logging
» npm install ngx-logger
Update for Angular version 9
The source files have been moved but you can still debug this way if you do the following steps
- In devtools, select the sources tab
- Press CTRL + P
- Type in the name of the file you want to debug

Valid for versions below 9
The other answers are completely valid answers but having been using Angular for around 18 months now I tend to do it in the browser - chrome tools!
Run ng test then f12 and find the spec file via the webpack context. Add a breakpoint(s) and refresh and it will hit said breakpoints. As per screenshot
This is what worked for me with:
- Angular 9.0.6 + Visual Studio Code 1.43.2
- Angular 8.2.13 + Visual Studio Code 1.39.2
- Angular 7, Angular CLI 1.0.* and Chrome on Windows 7.
Change configuration files
In your project root directory open karma.conf.js. Right after singleRun: false add , followed by this section:
customLaunchers: {
ChromeDebug: {
base: 'Chrome',
flags: [ '--remote-debugging-port=9333' ]
}
}
Add configuration to .vscode/launch.json.
For versions 8.* - 9.* (note
"pathMappingsection!):{ "type": "chrome", "request": "attach", "name": "Unit tests", "address": "localhost", "port": 9333, "sourceMaps": true, "webRoot": "${workspaceFolder}", "pathMapping": { "/_karma_webpack_": "${workspaceFolder}" } },For version 7.*:
{ "type": "chrome", "request": "attach", "name": "Unit tests", "address": "localhost", "port": 9333, "sourceMaps": true, "webRoot": "${workspaceFolder}" },
Start debugging
Run
ng test --browsers ChromeDebugWait for Chrome browser to start. You will see something like this in command line:
01 06 2017 16:07:29.276:INFO [launcher]: Launching browser ChromeDebug with unlimited concurrencySet the breakpoint in one of your
.spec.tsfiles.In Visual Studio Code choose
Unit testsdebug configuration and hit F5 ("Start Debugging" button).Press
Shift+Ctrl+F5or refresh the Chrome window to rerun the tests and hit the breakpoint.
For convenience
You can also modify your package.json and add a new script:
"test-debug": "ng test --browsers ChromeDebug",
Then next time you want to start ng test with debugging just run:
npm run test-debug
References:
- Debugging Jasmine Unit tests running with Karma runner in VS Code
- Debugging Karma tests with VSCode
- Angular CLI 8.1.3
Debug Unit Testsconfiguration - Unverified breakpoint - microsoft/vscode-recipes - Chrome Debugging with Angular CLI
The short answer for this is: no, not really.
Once your application hass been configured through your .config() block, no further configuration can take place after the application has bootstrapped.
This is due to the way providers work; they're only available at configuration time. There might be a way to force the configuration, and then manually re-inject the new $log service into all of your controllers, but if there is a way to do that, I'm not sure how.
I've decorated $log.debug(...) to change the loglevel at runtime.
Looking at Enhancing AngularJS Logging using Decorators, I got the idea for the following code snippet:
(function () {
var KEY = "debugEnabled";
angular.module("service.config", [])
.config(function ($provide, $logProvider) {
// AngularJS has debug enabled by default, but just to be sure...
$logProvider.debugEnabled(true);
// Disabling localStorageDebug (if not set)
if (localStorage.getItem(KEY) === null) {
localStorage.setItem(KEY, "false");
}
// add a check for localStorageDebug before actually calling $log.debug(...)
$provide.decorator('$log', function ($delegate) {
var debugFunction = $delegate.debug;
$delegate.debug = function () {
if (localStorage.getItem(KEY) !== "false") {
debugFunction.apply(undefined, arguments)
}
};
return $delegate;
});
})
.service("ConfigService", function ($log) {
this.debugEnabled = function (flag) {
$log.info("Setting debugEnabled to " + flag);
localStorage.setItem(KEY, flag.toString());
}
});
})();
// exposing ConfigService to global scope (be aware of possible clashes!),
// therefore making it easily accessible from the console
var cfg;
window.onload = function () {
cfg = angular.element(document.body).injector().get("ConfigService");
};
The decorator only forwards calls to $log.debug if debugEnabled is set to true in your local storage - the value can be changed through the ConfigService service.
Now you can just call ConfigService#debugEnabled with the value you've loaded from your server to change the loglevel.
Thanks to the last four lines, you can also simply call cfg.debugEnabled(true) on your console to enable debug mode at runtime.
If you don't like to type into the console, you could avoid the global cfg and use javascript bookmarks (or elements on your website) to change the log level.
» npm install ng-logger
Use browser.manage().logs().get('browser')
browser.manage().logs().get('browser').then(function(browserLogs) {
// browserLogs is an array of objects with level and message fields
browserLogs.forEach(function(log){
if (log.level.value > 900) { // it's an error log
console.log('Browser console error!');
console.log(log.message);
}
});
});
A general misconception is console.log will log the things in your browser. That is incorrect. When you run your tests, along with the results of tests you should see the console.log() values also in the terminal. Browser console is completely different from this.
A general example:
it('get name as John', function(){
element(by.id('name')).getText().then(function(value){
console.log(value);
})
});
Results in Terminal:
John
get name as John - pass
Hope it helps.