feat: 로그 시스템 구현 및 관련 클래스 추가

This commit is contained in:
2025-12-29 08:40:01 +00:00
parent e0eb768e2e
commit 27cc016804
13 changed files with 630 additions and 11 deletions
+62
View File
@@ -0,0 +1,62 @@
import { formatLogText } from './formatter.js';
import {
type LogContext,
type LogEntryDraft,
type LogEntryRecord,
LogFormat,
LogScope,
} from './types.js';
const shouldDropEntry = (entry: LogEntryDraft): boolean => {
if (entry.scope === LogScope.GENERAL && !entry.generalId) {
return true;
}
if (entry.scope === LogScope.NATION && !entry.nationId) {
return true;
}
if (entry.scope === LogScope.USER && !entry.userId) {
return true;
}
return false;
};
export const finalizeLogEntry = (
entry: LogEntryDraft,
context: LogContext
): LogEntryRecord | null => {
if (shouldDropEntry(entry)) {
return null;
}
const format = entry.format ?? LogFormat.RAWTEXT;
const text = formatLogText(entry.text, format, context.year, context.month);
const record: LogEntryRecord = {
scope: entry.scope,
category: entry.category,
text,
year: context.year,
month: context.month,
};
if (entry.generalId !== undefined) {
record.generalId = entry.generalId;
}
if (entry.nationId !== undefined) {
record.nationId = entry.nationId;
}
if (entry.userId !== undefined) {
record.userId = entry.userId;
}
if (entry.subType !== undefined) {
record.subType = entry.subType;
}
if (entry.meta !== undefined) {
record.meta = entry.meta;
}
if (context.at !== undefined) {
record.createdAt = context.at;
}
return record;
};