5

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.

Constantin Groß
  • 10,719
  • 4
  • 24
  • 50
shreyansh
  • 1,637
  • 4
  • 26
  • 46

1 Answers1

3

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:

Alok
  • 1,290
  • 1
  • 11
  • 21