Added and implemented a rudimentary logger

This commit is contained in:
Daniel Quinn
2016-02-14 16:09:52 +00:00
parent 88acf50fe0
commit 7843ea5037
14 changed files with 142 additions and 36 deletions

0
src/logger/__init__.py Normal file
View File

12
src/logger/admin.py Normal file
View File

@@ -0,0 +1,12 @@
from django.contrib import admin
from .models import Log
class LogAdmin(admin.ModelAdmin):
list_display = ("message", "level", "component")
list_filter = ("level", "component",)
admin.site.register(Log, LogAdmin)

5
src/logger/apps.py Normal file
View File

@@ -0,0 +1,5 @@
from django.apps import AppConfig
class LoggerConfig(AppConfig):
name = 'logger'

View File

@@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9 on 2016-02-14 16:08
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Log',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('time', models.DateTimeField(auto_now_add=True)),
('message', models.TextField()),
('level', models.PositiveIntegerField(choices=[(1, 'Error'), (2, 'Warning'), (3, 'Informational'), (4, 'Debugging')], default=3)),
('component', models.PositiveIntegerField(choices=[(1, 'Consumer'), (2, 'Mail Fetcher')])),
],
),
]

View File

47
src/logger/models.py Normal file
View File

@@ -0,0 +1,47 @@
from django.db import models
class Log(models.Model):
LEVEL_ERROR = 1
LEVEL_WARNING = 2
LEVEL_INFO = 3
LEVEL_DEBUG = 4
LEVELS = (
(LEVEL_ERROR, "Error"),
(LEVEL_WARNING, "Warning"),
(LEVEL_INFO, "Informational"),
(LEVEL_DEBUG, "Debugging"),
)
COMPONENT_CONSUMER = 1
COMPONENT_MAIL = 2
COMPONENTS = (
(COMPONENT_CONSUMER, "Consumer"),
(COMPONENT_MAIL, "Mail Fetcher")
)
time = models.DateTimeField(auto_now_add=True)
message = models.TextField()
level = models.PositiveIntegerField(choices=LEVELS, default=LEVEL_INFO)
component = models.PositiveIntegerField(choices=COMPONENTS)
@classmethod
def error(cls, message, component):
cls.objects.create(
message=message, level=cls.LEVEL_ERROR, component=component)
@classmethod
def warning(cls, message, component):
cls.objects.create(
message=message, level=cls.LEVEL_WARNING, component=component)
@classmethod
def info(cls, message, component):
cls.objects.create(
message=message, level=cls.LEVEL_INFO, component=component)
@classmethod
def debug(cls, message, component):
cls.objects.create(
message=message, level=cls.LEVEL_DEBUG, component=component)

3
src/logger/tests.py Normal file
View File

@@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

3
src/logger/views.py Normal file
View File

@@ -0,0 +1,3 @@
from django.shortcuts import render
# Create your views here.