From b530229e9025d9e0dc4b25e22115b77cb37c728f Mon Sep 17 00:00:00 2001 From: zhaoyingbo Date: Tue, 13 Aug 2024 01:30:15 +0000 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BF=AE=E6=94=B9=E6=89=93=E5=8D=B0?= =?UTF-8?q?=E9=80=BB=E8=BE=91=20&=20=E8=AF=B7=E6=B1=82=E7=AD=89=E5=BE=85?= =?UTF-8?q?=E7=BB=93=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controllers/manageMrEvent/summaryMr.ts | 2 +- index.ts | 6 ++--- ...4ce4c791e6f91cf40117d4a85785c6b-audit.json | 15 ----------- log/index.ts | 26 +++++++++++++++---- routes/event/index.ts | 1 + ...4ce4c791e6f91cf40117d4a85785c6b-audit.json | 15 ----------- 6 files changed, 26 insertions(+), 39 deletions(-) delete mode 100644 log/.477ef71694ce4c791e6f91cf40117d4a85785c6b-audit.json delete mode 100644 test/log/.477ef71694ce4c791e6f91cf40117d4a85785c6b-audit.json diff --git a/controllers/manageMrEvent/summaryMr.ts b/controllers/manageMrEvent/summaryMr.ts index 1d35f30..97d74ba 100644 --- a/controllers/manageMrEvent/summaryMr.ts +++ b/controllers/manageMrEvent/summaryMr.ts @@ -44,7 +44,7 @@ const summaryMr = async ( const { content: summarize } = await codeChatBot.invoke(summarizePrompt) if (!summarize) throw new Error("Empty summarize") // 记录总结日志 - logger.debug(`summarize for Mr: ${summarize}`) + logger.info(`summarize for Mr: ${summarize}`) return summarize as string } catch { // 记录错误日志 diff --git a/index.ts b/index.ts index 679e2ac..790b02f 100644 --- a/index.ts +++ b/index.ts @@ -14,9 +14,9 @@ const PREFIX = "/gitlab_monitor" const server = Bun.serve({ async fetch(req) { + // 添加请求ID + const logger = loggerIns.child({ requestId: uuid() }) try { - // 添加请求ID - const logger = loggerIns.child({ requestId: uuid() }) // 路由处理 const { exactCheck, fullCheck } = makeCheckPathTool(req.url, PREFIX) // 非根路由打印 @@ -29,7 +29,7 @@ const server = Bun.serve({ return netTool.ok("hello, there is gitlab monitor, glade to serve you!") } catch (error: any) { // 错误处理 - console.error("🚀 ~ serve ~ error", error) + logger.error(`server error: ${error.message}`) return netTool.serverError(error.message || "server error") } }, diff --git a/log/.477ef71694ce4c791e6f91cf40117d4a85785c6b-audit.json b/log/.477ef71694ce4c791e6f91cf40117d4a85785c6b-audit.json deleted file mode 100644 index 2d79bc6..0000000 --- a/log/.477ef71694ce4c791e6f91cf40117d4a85785c6b-audit.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "keep": { - "days": true, - "amount": 14 - }, - "auditLog": "log/.477ef71694ce4c791e6f91cf40117d4a85785c6b-audit.json", - "files": [ - { - "date": 1723259039565, - "name": "log/application-2024-08-10.log", - "hash": "fdd4f67d11fe79d1aedf242b8d2e1894fbd6a4679331098818c2324ec81678cd" - } - ], - "hashType": "sha256" -} \ No newline at end of file diff --git a/log/index.ts b/log/index.ts index 107b7b8..4fd6aad 100644 --- a/log/index.ts +++ b/log/index.ts @@ -4,21 +4,37 @@ import winston, { format } from "winston" const isProd = process.env.NODE_ENV === "production" -const dailyRotateFileTransport = new winston.transports.DailyRotateFile({ - filename: "./log/application-%DATE%.log", +const dailyRotateFileTransport4Info = new winston.transports.DailyRotateFile({ + level: "info", + filename: "/home/work/log/egg-info-%DATE%.log", datePattern: "YYYY-MM-DD", zippedArchive: true, maxSize: "20m", maxFiles: "14d", }) -const transports: any[] = [new winston.transports.Console()] +const dailyRotateFileTransport4Debug = new winston.transports.DailyRotateFile({ + level: "debug", + filename: "/home/work/log/egg-debug-%DATE%.log", + datePattern: "YYYY-MM-DD", + zippedArchive: true, + maxSize: "20m", + maxFiles: "14d", +}) + +const transports: any[] = [ + new winston.transports.Console({ + level: "info", + }), +] + if (isProd) { - transports.push(dailyRotateFileTransport) + transports.push(dailyRotateFileTransport4Info) + transports.push(dailyRotateFileTransport4Debug) } const loggerIns = winston.createLogger({ - level: "info", + level: "silly", format: format.combine( format.colorize({ level: !isProd, diff --git a/routes/event/index.ts b/routes/event/index.ts index d95e2c4..d70a95c 100644 --- a/routes/event/index.ts +++ b/routes/event/index.ts @@ -22,6 +22,7 @@ export const manageGitlabEventReq = async ( // 处理流水线钩子 if (eventType === "Pipeline Hook") { const body = (await req.json()) as Gitlab.PipelineEvent + logger.debug(`body: ${JSON.stringify(body)}`) const params = new URLSearchParams(req.url.split("?")[1]) return managePipelineEvent.manageRawEvent(body, apiKey, params) } diff --git a/test/log/.477ef71694ce4c791e6f91cf40117d4a85785c6b-audit.json b/test/log/.477ef71694ce4c791e6f91cf40117d4a85785c6b-audit.json deleted file mode 100644 index aedd43e..0000000 --- a/test/log/.477ef71694ce4c791e6f91cf40117d4a85785c6b-audit.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "keep": { - "days": true, - "amount": 14 - }, - "auditLog": "log/.477ef71694ce4c791e6f91cf40117d4a85785c6b-audit.json", - "files": [ - { - "date": 1723423178431, - "name": "log/application-2024-08-12.log", - "hash": "0bc427a58e73e382ac12bffa78e2d17ab09717e51a940fe5d71f786f5f1e6bcf" - } - ], - "hashType": "sha256" -} \ No newline at end of file