mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-08-10 00:18:57 +00:00
Added and implemented a rudimentary logger
This commit is contained in:
0
src/logger/__init__.py
Normal file
0
src/logger/__init__.py
Normal file
12
src/logger/admin.py
Normal file
12
src/logger/admin.py
Normal 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
5
src/logger/apps.py
Normal file
@@ -0,0 +1,5 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class LoggerConfig(AppConfig):
|
||||
name = 'logger'
|
26
src/logger/migrations/0001_initial.py
Normal file
26
src/logger/migrations/0001_initial.py
Normal 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')])),
|
||||
],
|
||||
),
|
||||
]
|
0
src/logger/migrations/__init__.py
Normal file
0
src/logger/migrations/__init__.py
Normal file
47
src/logger/models.py
Normal file
47
src/logger/models.py
Normal 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
3
src/logger/tests.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
3
src/logger/views.py
Normal file
3
src/logger/views.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.shortcuts import render
|
||||
|
||||
# Create your views here.
|
Reference in New Issue
Block a user