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 <[email protected]> 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 [email protected]. > 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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAMKMUjsbBoAZXMzoJKdqMpVis9WOScOEDm_qWig%3DraDgVfdyBQ%40mail.gmail.com.

