--To check the operation of the pip package whose source is open to the public, create a package with logger and install it locally.
--Check the currently installed version
- pip list | grep django-allauth
--Clone source code from GitHub
- mkdir django-allauth-with-log && cd django-allauth-with-log
- git clone https://github.com/pennersr/django-allauth.git
- cd django-allauth
vi allauth/__init__.py
#VERSION = (0, 44, 0, "dev", 0)
VERSION = (0, 44, 0, "dev", 99)
pip uninstall django-allauth
--Move to a directory one level above the directory containing setup.py
- cd ..
--Install by specifying a directory with pip
- pip install ./django-allauth/
pip list | grep django-allauth
--If the version number django-allauth 0.44.0.dev99
rewritten above appears, it is successful.
--Add a configuration file and load it from ʻallauth / app_settings.py`
from .logging_settings import * #add to
vi allauth/logging_settings.py
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'django.server': {
'()': 'django.utils.log.ServerFormatter',
'format': '[%(server_time)s] %(message)s a',
},
'develop': {
'format': '%(asctime)s [%(levelname)s] %(message)s'
},
},
'handlers': {
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
'formatter': 'develop',
},
'django.server': {
'level': 'INFO',
'class': 'logging.StreamHandler',
'formatter': 'django.server',
},
},
'loggers': {
'': {
'handlers': ['console'],
'level': 'DEBUG',
'propagate': False,
},
'django': {
'handlers': ['console'],
'level': 'INFO',
},
'django.server': {
'handlers': ['django.server'],
'level': 'INFO',
'propagate': False,
},
}
}
--For example, add the following to ʻallauth / account / views.py`
--logger settings
import sys
import logging
logger = logging.getLogger(__name__)
--Add the following anywhere (eg def dispatch
in class SignupView
)
logger.info(f'class={self.__class__.__name__}, function={sys._getframe().f_code.co_name}, Line={sys._getframe().f_lineno} called.')
--Note that the class name is the name of the inheritance destination?
pip uninstall -y django-allauth
pip install ./django-allauth/
--If you get Successfully installed django-allauth-0.44.99.dev0
, you're successful.--Start the server, access the URL like http://127.0.0.1:8000/member/signup/
, and it is OK if it is displayed on the console as below.
2020-11-03 01:23:45,678 [INFO] class=SignupView, function=dispatch, Line=238 called.
Recommended Posts