Error Logging With Angular and log4javascript

Angular is an awesome framework and plays very well with other libraries and is easy to integrate.  Angular come with a built-in log service which you can simply access by injecting $log; but I like the log4javascript library…

You can easily overwrite the default $log service by defining it in your app as such:

Basically all this is doing is creating an instance of logger and returning it…  Now I can use the log4javascript logger anywhere in my angular app.  This means I can log to a web service, or use any of the many log4javascript appenders.  Here is how I use it log to a web service.

To use it in my controller, I simply add $log as a dependency and call any of the methods on the logger i.e. info, warn, debug, etc…