$log not working with iOS debugger?


#1

I rewrote a big portion of our application today to use $log instead of invoking console.log directly.

Now I no longer see any debug output in the shell when I run cordova run ios. Has anyone else run into this?


#2

This is caused by $log being instantiated before the Console plugin is loaded. $log will store a reference to window.console, but window.console is replaced later on.

The solution for me was to programmatically instantiate $log after $ionicPlatform.ready is signaled.

Before

appModule.controller( "ApplicationController", ApplicationController );
ApplicationController.$inject = [ "$ionicPlatform", "$log" ];
function ApplicationController( $ionicPlatform, $log ) {
	$log.info( "Application Controller loaded" );
	$ionicPlatform.ready( function() {
		$log.info( "Ionic Platform ready" );
	} );
}

After

appModule.controller( "ApplicationController", ApplicationController );
ApplicationController.$inject = [ "$ionicPlatform" ];
function ApplicationController( $ionicPlatform ) {
	console.log( "Application Controller loaded" );
	$ionicPlatform.ready( function() {
		var injector = angular.element( document.body ).injector();
		var $log = injector.get( "$log" );
		$log.info( "Ionic Platform ready" );
	} );
}