-
Notifications
You must be signed in to change notification settings - Fork 27.4k
feat(ngLog): provides support to debug the application in chosen level #8303
base: master
Are you sure you want to change the base?
Conversation
ngLog can now log in window console based on a debug level, that can be redefined in LogProvider. Defaults to 'debug'.
Thanks for the PR! Please check the items below to help us merge this faster. See the contributing docs for more information.
If you need to make changes to your pull request, you can update the commit with Thanks again for your help! |
@jeffbcross Please, take a look at this. I just pushed a chore that changes the log hierarchy and added tests. Thanks! |
I actually think this approach assumes too much. I'd actually prefer something like this: It provides more granular control over logging, and makes less assumptions. I don't think the framework should be making decisions regarding logging tier hierarchies and disabling them en-masse based on predefined strings. |
@thebigredgeek I've worked with some server-side frameworks like Yii (php), Django, Flask and Tornado (python). And in all of them, as far as I know, you don't choose or toggle each kind of log, you only choose the Application Debug Level. Obviously, Angular.js does not need to be like such frameworks and it can be different in very features and aspects, but what I'm trying to do, is bring the power we have in those frameworks to Angular.js and use it in the same way, creating a pattern to be followed by developers independent of the framework or language. Some good links: |
I understand that this is somewhat normal, but what I don't understand is why you would want less control over logging? It seems a bit ridiculous to want string-based logger toggling abstraction rather than boolean-based granular control over each type of logger entity. Can you explain what benefit a more abstract approach offers versus just extended the same functionality that is already present? Your approach would also be a breaking change, as there are many people who are already using |
This feature will add more control over logging by changing your level of debug in determined environments.
It's not a change, the existing functionality will be intact and can be extended. angular.module('myModule')
.config([
'$logProvider',
function($logProvider) {
// set the level based on your environment or on your needs of debugging
$logProvider.debugLevel('info');
}
])
.controller('MyController', [
'$scope',
'$log',
function($scope, $log) {
$scope.myFunction = function(user) {
$log.log('entered in myFunction');
if ($scope.checkIfUserExists(user)) {
$log.warn('user already exists');
return;
}
if ($scope.saveUser(user)) {
$log.info('user saved');
} else {
$log.error('error on save user');
}
};
}
]); |
Again, I am not sure why we would want to create pre-seeded logging "template" settings like this, rather than doing something like:
I think your approach is great, but I also think it is far too opinionated to be built into angular core. If you want to create string-based levels, you can just roll your own provider around this very schema. It's unopinionated and low level, which IMO is how it should be. TL;DR; - I think we want to keep Angular core pretty unopinonated. I think that something like environment-base log configuration should be deferred to the programmer implementing. Rolling your own provider around an extension of the existing |
All I can say, is this is just an easy-add feature that all other frameworks that I've been worked provide to me. If you want to add a "single-level-debug" control feature, you can do it. I think it will not conflict with this feature. But, in my opinion, "debug-level-hierarchy" is more efficient and its pattern can be found in all major frameworks that I've seen. |
02dc2aa
to
fd2d6c0
Compare
cad9560
to
f294244
Compare
e8dc429
to
e83fab9
Compare
4dd5a20
to
998c61c
Compare
+1 |
Request Type: feature
How to reproduce:
Component(s): jqLite
Impact: large
Complexity: small
This issue is related to:
Detailed Description:
I think we need to set a level to debug the application. So, I've developed a feature that add an extra behaviour to $log. In the $logProvider, I created a method called debugLevel that receives a string as parameter and, based on that parameter, the application change its debug level.
With this feature, setting debugLevel to 'error' will log only error messages, while setting 'log' will debug the application in a "trace like" mode.
I'm not able to write tests for this feature and I think the code can be cleaner, but it helped me a lot.In the two last commits I've added two tests to this feature: one to ensure that if debugLevel is not defined, the application will log as default and one setting the level to 'warn'.Other Comments:
ngLog can now log in window console based on a debug level, that can be redefined in LogProvider. Defaults to 'log'.