From 632af91878b37409afbfe3603967a552011f3fd1 Mon Sep 17 00:00:00 2001 From: syuilo Date: Fri, 22 Oct 2021 20:41:15 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=87=E3=83=BC=E3=82=BF=E3=83=99=E3=83=BC?= =?UTF-8?q?=E3=82=B9=E3=81=AB=E3=83=AD=E3=82=B0=E3=82=92=E4=BF=9D=E5=AD=98?= =?UTF-8?q?=E3=81=99=E3=82=8B=E3=81=AE=E3=82=92=E5=BB=83=E6=AD=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Close #7878 --- CHANGELOG.md | 4 + migration/1634902659689-delete-log.ts | 13 +++ src/client/pages/admin/index.vue | 6 -- src/client/pages/admin/logs.vue | 97 ------------------- src/db/postgre.ts | 2 - src/models/entities/log.ts | 46 --------- src/models/index.ts | 2 - src/server/api/endpoints/admin/logs.ts | 126 ------------------------- src/services/logger.ts | 16 ---- 9 files changed, 17 insertions(+), 295 deletions(-) create mode 100644 migration/1634902659689-delete-log.ts delete mode 100644 src/client/pages/admin/logs.vue delete mode 100644 src/models/entities/log.ts delete mode 100644 src/server/api/endpoints/admin/logs.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index a4996cfe4..1a6741184 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,10 @@ - クライアント: リモートノートで意図せずローカルカスタム絵文字が使われてしまうことがあるのを修正 - ActivityPub: not reacted な Undo.Like がinboxに滞留するのを修正 +### Changes +- データベースにログを保存しないようになりました + - ログを永続化したい場合はsyslogを利用してください + ## 12.92.0 (2021/10/16) ### Improvements diff --git a/migration/1634902659689-delete-log.ts b/migration/1634902659689-delete-log.ts new file mode 100644 index 000000000..5264d585c --- /dev/null +++ b/migration/1634902659689-delete-log.ts @@ -0,0 +1,13 @@ +import {MigrationInterface, QueryRunner} from "typeorm"; + +export class deleteLog1634902659689 implements MigrationInterface { + name = 'deleteLog1634902659689' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`DROP TABLE "log"`); + } + + public async down(queryRunner: QueryRunner): Promise { + } + +} diff --git a/src/client/pages/admin/index.vue b/src/client/pages/admin/index.vue index 7094f2d4b..416e68206 100644 --- a/src/client/pages/admin/index.vue +++ b/src/client/pages/admin/index.vue @@ -201,11 +201,6 @@ export default defineComponent({ text: i18n.locale.database, to: '/admin/database', active: page.value === 'database', - }, { - icon: 'fas fa-stream', - text: i18n.locale.logs, - to: '/admin/logs', - active: page.value === 'logs', }], }]); const component = computed(() => { @@ -220,7 +215,6 @@ export default defineComponent({ case 'announcements': return defineAsyncComponent(() => import('./announcements.vue')); case 'ads': return defineAsyncComponent(() => import('./ads.vue')); case 'database': return defineAsyncComponent(() => import('./database.vue')); - case 'logs': return defineAsyncComponent(() => import('./logs.vue')); case 'abuses': return defineAsyncComponent(() => import('./abuses.vue')); case 'settings': return defineAsyncComponent(() => import('./settings.vue')); case 'files-settings': return defineAsyncComponent(() => import('./files-settings.vue')); diff --git a/src/client/pages/admin/logs.vue b/src/client/pages/admin/logs.vue deleted file mode 100644 index 74aea0fc4..000000000 --- a/src/client/pages/admin/logs.vue +++ /dev/null @@ -1,97 +0,0 @@ - - - diff --git a/src/db/postgre.ts b/src/db/postgre.ts index 0b635ea18..4f4047b61 100644 --- a/src/db/postgre.ts +++ b/src/db/postgre.ts @@ -8,7 +8,6 @@ import { entities as charts } from '@/services/chart/entities'; import { dbLogger } from './logger'; import * as highlight from 'cli-highlight'; -import { Log } from '@/models/entities/log'; import { User } from '@/models/entities/user'; import { DriveFile } from '@/models/entities/drive-file'; import { DriveFolder } from '@/models/entities/drive-folder'; @@ -144,7 +143,6 @@ export const entities = [ PageLike, GalleryPost, GalleryLike, - Log, DriveFile, DriveFolder, Poll, diff --git a/src/models/entities/log.ts b/src/models/entities/log.ts deleted file mode 100644 index 182a9fbed..000000000 --- a/src/models/entities/log.ts +++ /dev/null @@ -1,46 +0,0 @@ -import { Entity, PrimaryColumn, Index, Column } from 'typeorm'; -import { id } from '../id'; - -@Entity() -export class Log { - @PrimaryColumn(id()) - public id: string; - - @Index() - @Column('timestamp with time zone', { - comment: 'The created date of the Log.' - }) - public createdAt: Date; - - @Index() - @Column('varchar', { - length: 64, array: true, default: '{}' - }) - public domain: string[]; - - @Index() - @Column('enum', { - enum: ['error', 'warning', 'info', 'success', 'debug'] - }) - public level: string; - - @Column('varchar', { - length: 8 - }) - public worker: string; - - @Column('varchar', { - length: 128 - }) - public machine: string; - - @Column('varchar', { - length: 2048 - }) - public message: string; - - @Column('jsonb', { - default: {} - }) - public data: Record; -} diff --git a/src/models/index.ts b/src/models/index.ts index 059a3d7b8..4c6f19eaf 100644 --- a/src/models/index.ts +++ b/src/models/index.ts @@ -13,7 +13,6 @@ import { UserRepository } from './repositories/user'; import { NoteRepository } from './repositories/note'; import { DriveFileRepository } from './repositories/drive-file'; import { DriveFolderRepository } from './repositories/drive-folder'; -import { Log } from './entities/log'; import { AccessToken } from './entities/access-token'; import { UserNotePining } from './entities/user-note-pining'; import { SigninRepository } from './repositories/signin'; @@ -108,7 +107,6 @@ export const Signins = getCustomRepository(SigninRepository); export const MessagingMessages = getCustomRepository(MessagingMessageRepository); export const ReversiGames = getCustomRepository(ReversiGameRepository); export const ReversiMatchings = getCustomRepository(ReversiMatchingRepository); -export const Logs = getRepository(Log); export const Pages = getCustomRepository(PageRepository); export const PageLikes = getCustomRepository(PageLikeRepository); export const GalleryPosts = getCustomRepository(GalleryPostRepository); diff --git a/src/server/api/endpoints/admin/logs.ts b/src/server/api/endpoints/admin/logs.ts deleted file mode 100644 index 776403a62..000000000 --- a/src/server/api/endpoints/admin/logs.ts +++ /dev/null @@ -1,126 +0,0 @@ -import $ from 'cafy'; -import define from '../../define'; -import { Logs } from '@/models/index'; -import { Brackets } from 'typeorm'; - -export const meta = { - tags: ['admin'], - - requireCredential: true as const, - requireModerator: true, - - params: { - limit: { - validator: $.optional.num.range(1, 100), - default: 30 - }, - - level: { - validator: $.optional.nullable.str, - default: null - }, - - domain: { - validator: $.optional.nullable.str, - default: null - } - }, - - res: { - type: 'array' as const, - optional: false as const, nullable: false as const, - items: { - type: 'object' as const, - optional: false as const, nullable: false as const, - properties: { - id: { - type: 'string' as const, - optional: false as const, nullable: false as const, - format: 'id', - example: 'xxxxxxxxxx', - }, - createdAt: { - type: 'string' as const, - optional: false as const, nullable: false as const, - format: 'date-time', - }, - domain: { - type: 'array' as const, - optional: false as const, nullable: false as const, - items: { - type: 'string' as const, - optional: true as const, nullable: false as const - } - }, - level: { - type: 'string' as const, - optional: false as const, nullable: false as const - }, - worker: { - type: 'string' as const, - optional: false as const, nullable: false as const - }, - machine: { - type: 'string' as const, - optional: false as const, nullable: false as const, - }, - message: { - type: 'string' as const, - optional: false as const, nullable: false as const, - }, - data: { - type: 'object' as const, - optional: false as const, nullable: false as const - } - } - } - } -}; - -export default define(meta, async (ps) => { - const query = Logs.createQueryBuilder('log'); - - if (ps.level) query.andWhere('log.level = :level', { level: ps.level }); - - if (ps.domain) { - const whiteDomains = ps.domain.split(' ').filter(x => !x.startsWith('-')); - const blackDomains = ps.domain.split(' ').filter(x => x.startsWith('-')).map(x => x.substr(1)); - - if (whiteDomains.length > 0) { - query.andWhere(new Brackets(qb => { - for (const whiteDomain of whiteDomains) { - let i = 0; - for (const subDomain of whiteDomain.split('.')) { - const p = `whiteSubDomain_${subDomain}_${i}`; - // SQL is 1 based, so we need '+ 1' - qb.orWhere(`log.domain[${i + 1}] = :${p}`, { [p]: subDomain }); - i++; - } - } - })); - } - - if (blackDomains.length > 0) { - query.andWhere(new Brackets(qb => { - for (const blackDomain of blackDomains) { - qb.andWhere(new Brackets(qb => { - const subDomains = blackDomain.split('.'); - let i = 0; - for (const subDomain of subDomains) { - const p = `blackSubDomain_${subDomain}_${i}`; - // 全体で否定できないのでド・モルガンの法則で - // !(P && Q) を !P || !Q で表す - // SQL is 1 based, so we need '+ 1' - qb.orWhere(`log.domain[${i + 1}] != :${p}`, { [p]: subDomain }); - i++; - } - })); - } - })); - } - } - - const logs = await query.orderBy('log.createdAt', 'DESC').take(ps.limit!).getMany(); - - return logs; -}); diff --git a/src/services/logger.ts b/src/services/logger.ts index 8e783e67f..67ee44125 100644 --- a/src/services/logger.ts +++ b/src/services/logger.ts @@ -1,11 +1,7 @@ import * as cluster from 'cluster'; -import * as os from 'os'; import * as chalk from 'chalk'; import * as dateformat from 'dateformat'; import { envOption } from '../env'; -import { getRepository } from 'typeorm'; -import { Log } from '@/models/entities/log'; -import { genId } from '@/misc/gen-id'; import config from '@/config/index'; import * as SyslogPro from 'syslog-pro'; @@ -95,18 +91,6 @@ export default class Logger { null as never; send.bind(this.syslogClient)(message).catch(() => {}); - } else { - const Logs = getRepository(Log); - Logs.insert({ - id: genId(), - createdAt: new Date(), - machine: os.hostname(), - worker: worker.toString(), - domain: [this.domain].concat(subDomains).map(d => d.name), - level: level, - message: message.substr(0, 1000), // 1024を超えるとログが挿入できずエラーになり無限ループする - data: data, - } as Log).catch(() => {}); } } }