I was going through the angularJs
doc and came to know about log
, warn
, error
etc. Now to see the output we need to open the console, so my question are
if already console.log()
is there to see the errors in console, then what is the use of $log
, where is the place/scenerio that I must involve the use of $log
in my angularJs application
.
How can I make use of $log to store information in file about my logging activities.
Well, basic difference is $log is the AngularJs implementation of logging and a lot more than just spitting bits of strings and data to console, whereas console.log() is basic java script.
You pass $log as a service to your controllers, factories and other services. The plus about using $log is that you can extend and customize it.
For starters, I really like this for when I have to check what controller loaded and where things failed in a big application I can do so, by $log.info():
myApp.config(['$stateProvider', '$urlRouterProvider', '$logProvider', function ($stateProvider, $urlRouterProvider, $logProvider)
{
$urlRouterProvider.otherwise("/home");
$logProvider.debugEnabled(isDebugMode);
}]);
See the $logProvider that enables or disables logging depending on environment.
A lot more on extending the existing logger:
Here
And Here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With