I'm trying to use $log.debug("Foo"). How can it be turned on off. I can't find a sample anywhere. I think it need to be set in the config, but I cant seem to get that to work either.
Where does one set the on and off switch?
I'm trying to use $log.debug("Foo"). How can it be turned on off. I can't find a sample anywhere. I think it need to be set in the config, but I cant seem to get that to work either.
Where does one set the on and off switch?
$logProvider.debugEnabled(true)
This is only available in AngularJs 1.1.2 or later.
https://github.com/angular/angular.js/pull/1625
Here is an example of it being set.
http://plnkr.co/edit/HZCAoS?p=preview
By default it is on.
Based on Diego's response but adding some env config and making it shorter. You can simply run your app using:
NODE_ENV=development
orNODE_ENV=production
E.g.1.
NODE_ENV=development webpack-dev-server
E.g.2.
NODE_ENV=production node app.js
You can override the default $log behavior with a decorator to enhace the log level. This is an example:
This was inspired from the work of John Crosby at http://www.thekuroko.com/using-angulars-log-provider/
Well, Since the solution requires us to turn on
Verbose
flag, I think the best way to handle logging in angular would be to simply alter the nativeconsole.log
function in Production Environment for the entire application.That's it. In production environment, this should disable logging everywhere. Also there is no need to inject
$log
in every controller now. Simplyconsole.log("logging message")
works!You can also disable
console.info
,console.warn
,console.error
andconsole.debug
the same way as per your need.I have faced the same issue but it's not an issue to be solved by coding instead just enable it from browser console
Go to console of browser and set level to verbose