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.

Ravexina
  • 2,406
  • 2
  • 25
  • 41

1 Answers1

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.

Ravexina
  • 2,406
  • 2
  • 25
  • 41
  • 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? – blues May 20 '21 at 13:04