-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #111 from lihuacai168/feat/save-log
feat(system): save all log
- Loading branch information
Showing
12 changed files
with
107 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# !/usr/bin/python3 | ||
# -*- coding: utf-8 -*- | ||
|
||
# @Author: 花菜 | ||
# @File: log.py | ||
# @Time : 2023/9/17 22:25 | ||
# @Email: [email protected] | ||
|
||
import logging | ||
|
||
class DatabaseLogHandler(logging.Handler): | ||
def emit(self, record: logging.LogRecord) -> None: | ||
from system.models import LogRecord # 引入上面定义的LogRecord模型 | ||
LogRecord.objects.create( | ||
request_id=record.request_id, | ||
level=record.levelname, | ||
message=self.format(record), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.contrib import admin | ||
|
||
# Register your models here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class SystemConfig(AppConfig): | ||
name = 'system' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Generated by Django 2.2.17 on 2023-09-17 22:20 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='LogRecord', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('create_time', models.DateTimeField(auto_now_add=True, verbose_name='创建时间')), | ||
('update_time', models.DateTimeField(auto_now=True, verbose_name='更新时间')), | ||
('creator', models.CharField(max_length=20, null=True, verbose_name='创建人')), | ||
('updater', models.CharField(max_length=20, null=True, verbose_name='更新人')), | ||
('request_id', models.CharField(db_index=True, max_length=100, null=True)), | ||
('level', models.CharField(max_length=20)), | ||
('message', models.TextField(db_index=True)), | ||
], | ||
options={ | ||
'db_table': 'log_record', | ||
}, | ||
), | ||
] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from django.db import models | ||
|
||
from fastuser.models import BaseTable | ||
|
||
|
||
# Create your models here. | ||
|
||
|
||
class LogRecord(BaseTable): | ||
class Meta: | ||
db_table = "log_record" | ||
request_id = models.CharField(max_length=100, null=True, db_index=True) | ||
level = models.CharField(max_length=20) | ||
message = models.TextField(db_index=True) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.test import TestCase | ||
|
||
# Create your tests here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.shortcuts import render | ||
|
||
# Create your views here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
.git | ||
**/*.log | ||
**/*-log-* | ||
**/*.tar.gz | ||
Dockerfile | ||
.dockerignore | ||
node_modules | ||
dist | ||
*.md | ||
node_modules/ |