Browse Source

added logger

newsletter
Esther Kleinhenz 6 years ago
parent
commit
d01ed0085c
4 changed files with 61 additions and 8 deletions
  1. 4
    2
      application/models.py
  2. 4
    5
      application/views.py
  3. 3
    0
      log.txt
  4. 50
    1
      mysite/settings.py

+ 4
- 2
application/models.py View File

@@ -3,8 +3,10 @@ from django.contrib.auth.models import User
from django.utils import timezone
from taggit.managers import TaggableManager


class CustomUser(models.Model):
user = models.OneToOneField('auth.User', null = True, on_delete=models.CASCADE)
user = models.OneToOneField(
'auth.User', null=True, on_delete=models.CASCADE)
tags = TaggableManager()


@@ -23,4 +25,4 @@ class Post(models.Model):
self.save()

def __str__(self):
return self.title
return self.title

+ 4
- 5
application/views.py View File

@@ -18,12 +18,9 @@ import mysite.settings
import operator


# Create your views here.


def navlogin(request):

log = logging.getLogger('medinf')
log = logging.getLogger('mysite')
logout(request)
error = ""
if request.POST:
@@ -145,16 +142,18 @@ def student_page(request):

@login_required
def tag_list(request):
log = logging.getLogger('mysite')
u = CustomUser.objects.get(user=request.user)
tags= Tag.objects.filter(customuser=u)
arr=[]
arr.append(tags)
log.info("test".format(arr))
"""
for tag in tags:
arr.append(str(tag))
"""
listing = list(arr)
return render(request, 'tag_list.html', {'tags':tags})
return render(request, 'tag_list.html', locals())


class TagSearch(TagCanvasListView):

+ 3
- 0
log.txt View File

@@ -0,0 +1,3 @@
[16/Oct/2018 19:58:49] INFO [mysite:150] test
[16/Oct/2018 20:00:13] INFO [mysite:150] test
[16/Oct/2018 20:00:44] INFO [mysite:150] test

+ 50
- 1
mysite/settings.py View File

@@ -169,4 +169,53 @@ else:
'django.contrib.auth.backends.ModelBackend',
'mysite.ldap_backend.LdapBackend',
]
print(" --- Live stage --- ")
print(" --- Live stage --- ")



#Log Configuration
LOGGING = {
'version': 1,
'disable_existing_loggers': True,
'formatters': {
'standard': {
'format' : "[%(asctime)s] %(levelname)s [%(name)s:%(lineno)s] %(message)s",
'datefmt' : "%d/%b/%Y %H:%M:%S"
},
},
'handlers': {
'null': {
'level':'DEBUG',
'class':'logging.NullHandler',
},
'logfile': {
'level':'DEBUG',
'class':'logging.handlers.RotatingFileHandler',
'filename': os.path.join(BASE_DIR, 'log.txt'),
'maxBytes': 50000,
'backupCount': 2,
'formatter': 'standard',
},
'console':{
'level':'INFO',
'class':'logging.StreamHandler',
'formatter': 'standard'
},
},
'loggers': {
'django': {
'handlers':['console'],
'propagate': True,
'level':'WARN',
},
'django.db.backends': {
'handlers': ['console'],
'level': 'DEBUG',
'propagate': False,
},
'mysite': {
'handlers': ['console', 'logfile'],
'level': 'DEBUG',
},
}
}

Loading…
Cancel
Save