In a project based on angular-seed project, I am running unit tests with ./scripts/test.sh --log-level debug but none of the log messages that I see are coming from my app. How do I get to see them? In my app, I am logging with $log.
            Asked
            
        
        
            Active
            
        
            Viewed 4,469 times
        
    10
            
            
        
        jbasko
        
- 7,028
 - 1
 - 38
 - 51
 
- 
                    in the terminal you can only see console.log() calls defined in your spec file, not in your app – glepretre Feb 06 '14 at 12:26
 - 
                    See my answer below. I got to see my app logs. – jbasko Feb 06 '14 at 12:29
 
3 Answers
15
            
            
        Thanks.  As mentioned, tests can inject console for $log using $provide.  For posterity, $provide is not available via inject(function(...) { ... }) but instead must be injected into a function argument to module:
beforeEach(module('myapp', function($provide) {
  // Output messages
  $provide.value('$log', console);
}));
        Carl G
        
- 17,394
 - 14
 - 91
 - 115
 
- 
                    1Shouldn't @Carl get credit for this answer? I guess not, I didn't look at the time stamps. NM – Dave May 16 '15 at 20:34
 - 
                    Yes, I built on the earlier answer because it was not obvious to me how to properly override the `$log` service in a test. As mentioned here, `$provide` must be injected using `module`. – Carl G Jun 01 '16 at 18:15
 
12
            Got it working! Had I used console.log directly it would have worked but now that I am using $log I had to patch it in a beforeEach (looks like by default it wasn't wired by angularjs):
$provide.value('$log', console);
        jbasko
        
- 7,028
 - 1
 - 38
 - 51
 
4
            
            
        for clarity, you must structure it like this:
beforeEach(module('myapp'));
beforeEach(module('myapp', function($provide) {
  // Output messages
  $provide.value('$log', console);
})); 
        doug31415
        
- 275
 - 2
 - 9