Re: How to get username in django_requestlogging

2021-01-03 Thread Chetan Ganji
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 
wrote:

> I am using ‘django_requestlogging’ for the log file and I have followed
> 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+unsubscr...@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
> 
> .
>

-- 
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/CAMKMUjsbBoAZXMzoJKdqMpVis9WOScOEDm_qWig%3DraDgVfdyBQ%40mail.gmail.com.


Re: How to get username in django_requestlogging

2021-01-03 Thread Chetan Ganji
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  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 
> wrote:
>
>> I am using ‘django_requestlogging’ for the log file and I have followed
>> 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+unsubscr...@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
>> 
>> .
>>
>

-- 
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/CAMKMUjtrvcrqSM4p9N_KsZiu2Nc7CMOaSkKf1n_Ane8tT-%3D7vA%40mail.gmail.com.


Re: How to get username in django_requestlogging

2021-01-03 Thread Shailesh Yadav
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  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  
>> wrote:
>>
>>> I am using ‘django_requestlogging’ for the log file and I have followed 
>>> 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
>>>  
>>> 
>>> .
>>>
>>

-- 
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.