-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathmodels.py
35 lines (30 loc) · 1.08 KB
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import logging
from django.db import models
from six import python_2_unicode_compatible
from django.utils.translation import gettext_lazy as _
LOG_LEVELS = (
(logging.NOTSET, _('NotSet')),
(logging.INFO, _('Info')),
(logging.WARNING, _('Warning')),
(logging.DEBUG, _('Debug')),
(logging.ERROR, _('Error')),
(logging.FATAL, _('Fatal')),
)
@python_2_unicode_compatible
class StatusLog(models.Model):
logger_name = models.CharField(max_length=100)
level = models.PositiveSmallIntegerField(choices=LOG_LEVELS, default=logging.ERROR, db_index=True)
msg = models.TextField()
trace = models.TextField(blank=True, null=True)
create_datetime = models.DateTimeField(auto_now_add=True, verbose_name='Created at')
details = models.JSONField(
_("details"),
help_text=_("Additional info about the log (e.g. GET request path and query params)."),
blank=False,
null=True,
)
def __str__(self):
return self.msg
class Meta:
ordering = ('-create_datetime',)
verbose_name_plural = verbose_name = 'Logging'