Hi RyuCoder, Thanks Actually later I have found that this module is very old (2011) and it seems that the middleware no longer works with recent versions of Django. I am trying to implement 1st Answer by passing an extra parameter but not sure Filter where I need to define it and also it is compulsory?. https://stackoverflow.com/questions/10292082/django-logging-django-request-logger-and-extra-context
sentry => I think it is not open-source and need to take license to use in Prod env. On Sunday, January 3, 2021 at 11:12:26 PM UTC+5:30 RyuCoder wrote: > However, > > use sentry for logging on prod servers, it will make your life easier. > > Its free to get started ð > > On Sun, Jan 3, 2021, 11:08 PM Chetan Ganji <ganji....@gmail.com> wrote: > >> Hey, >> >> On that link it is mentioned as below. >> >> If any of this information cannot be extracted from the current request >> (or there is no current request), a hyphen '-' is substituted as a >> placeholder. >> >> Maybe you are trying with anonymous user? ð >> >> >> >> >> On Sat, Jan 2, 2021, 8:42 PM Shailesh Yadav <shailesh...@gmail.com> >> wrote: >> >>> I am using âdjango_requestloggingâ for the log file and I have followed >>> django_requestlogging <https://pypi.org/project/django-requestlogging/> >>> this >>> link and configured it as per the steps given. >>> >>> I am not getting the username in the log file instead of that I am >>> getting â-â. >>> >>> Please find the code details. >>> >>> >>> *step1*.Installed application >>> >>> INSTALLED_APPS = >>> >>> [ ------- ------ >>> >>> 'django_requestlogging', >>> >>> ] >>> >>> >>> *step2:* Created Middleware >>> >>> >>> from django.utils.deprecation import MiddlewareMixin from >>> django_requestlogging.middleware import LogSetupMiddleware as Original >>> class LogSetupMiddleware(MiddlewareMixin, Original): pass >>> >>> >>> *step3:* used in settings.py >>> >>> >>> MIDDLEWARE = [ âdjango.middleware.security.SecurityMiddlewareâ, >>> âdjango.contrib.sessions.middleware.SessionMiddlewareâ, >>> âdjango.middleware.common.CommonMiddlewareâ, >>> âdjango.middleware.csrf.CsrfViewMiddlewareâ, >>> âdjango.contrib.auth.middleware.AuthenticationMiddlewareâ, >>> âdjango.contrib.messages.middleware.MessageMiddlewareâ, >>> âdjango.middleware.clickjacking.XFrameOptionsMiddlewareâ, >>> âuser_visit.middleware.UserVisitMiddlewareâ, # >>> âdjango_requestlogging.middleware.LogSetupMiddlewareâ, >>> âapple.middleware1.LogSetupMiddlewareâ ] >>> >>> >>> >>> *step4:* Configuration >>> >>> >>> >>> >>> LOGGING = { >>> 'version': 1, >>> # Version of logging >>> 'disable_existing_loggers': False, >>> 'filters': { >>> # Add an unbound RequestFilter. >>> 'request': { >>> '()': 'django_requestlogging.logging_filters.RequestFilter', >>> }, >>> }, >>> 'formatters': { >>> 'request_format': { >>> 'format': '%(remote_addr)s "%(request_method)s ' >>> '%(path_info)s %(server_protocol)s" %(http_user_agent)s ' >>> '%(message)s %(asctime)s', >>> }, >>> >>> 'simple': { >>> 'format': '[%(asctime)s] - %(levelname)5s -:%(message)3s -" >>> %(username)5s' >>> }, >>> >>> }, >>> 'handlers': { >>> 'console': { >>> 'level': 'INFO', >>> 'class': 'logging.StreamHandler', >>> 'filters': ['request'], >>> 'formatter': 'simple', >>> }, >>> >>> 'file': { >>> 'level': 'INFO', >>> 'class': 'logging.FileHandler', >>> 'filename': 'icici.log', >>> 'formatter':'simple' >>> }, >>> }, >>> 'loggers': { >>> 'django': { >>> # Add your handlers that have the unbound request filter >>> 'handlers': ['console','file'], >>> 'level': 'DEBUG', >>> 'propagate': True, >>> # Optionally, add the unbound request filter to your >>> # application. >>> 'filters': ['request'], >>> }, >>> }, >>> } >>> >>> In the O/p Log file, I am getting. >>> >>> [2021-01-01 21:53:39,243] - INFO -:"GET /genesysall/ HTTP/1.1" 200 82259 >>> -" - >>> >>> Any help or hint on this how to get the username. >>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "Django users" group. >>> To unsubscribe from this group and stop receiving emails from it, send >>> an email to django-users...@googlegroups.com. >>> To view this discussion on the web visit >>> https://groups.google.com/d/msgid/django-users/f1f1adea-a087-42f6-b5ef-d3847b9bc43bn%40googlegroups.com >>> >>> <https://groups.google.com/d/msgid/django-users/f1f1adea-a087-42f6-b5ef-d3847b9bc43bn%40googlegroups.com?utm_medium=email&utm_source=footer> >>> . >>> >> -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/78b70d9e-596b-4155-8ee7-4ba9c15349f5n%40googlegroups.com.