0

What I'm experiencing is getting duplicate entries in my logs. I've looked around, and it seems that I have to set 'propagate': False in my loggers configuration which I have already done. However when I printout the logger.propagate it returns True. I even tried to manually set logger.propagate = False but it still returns True and I'm receiving duplicate entries in my logs.

What might be the cause of problem?

import logging
logger = logging.getLogger(__name__)
logger.propagate = False
class PostsListAPIView(ListAPIView):
    def get_queryset(self):
        # Getting both twice
        logger.error('Something went wrong!')  
        logger.error(logger.propagate)  # Returns True
        queryset = ...
        return queryset
 LOGGING = { 
      "version": 1,
      "disable_existing_loggers": False,
      "formatters": {
          "simple": {
              "format": "{levelname} {message}",
              "style": "{",
          }   
      },  
      "handlers": {
          "console": {
              "level": "DEBUG",
              "class": "logging.StreamHandler",
              "formatter": "simple",
          },  
      },  
      "loggers": {
          "app": {
              "level": "DEBUG",
              "handlers": ["console"],
              'propagate': False,
  
          }   
      },  
  }

I also tried setting "disable_existing_loggers": True, but it has no effects.

1 Answer 1

1

As for getting duplicate log entries, I found out that the cause is get_queryset method being called twice in order to display the forms as my BrowsableAPI is enabled.

However I still have not Idea why logger.propagate returns True.

Sign up to request clarification or add additional context in comments.

1 Comment

Most likely you are setting the propagate on a different logger. Have you checked that the value of __name__ is actually identical to the name of your logger?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.