Skip to content

Commit

Permalink
feat: improve access log
Browse files Browse the repository at this point in the history
  • Loading branch information
Yusuke4869 committed Sep 23, 2024
1 parent 4fb7872 commit 819dbb9
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/services/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,27 @@ export const sendAccessLog = async (c: Context) => {
if (!DISCORD_WEBHOOK_URL_ACCESS_LOG) return;

const info = getConnInfo(c);
const time = new Date().toLocaleString("en-US", {
timeZone: "Asia/Tokyo",
hour12: false,
month: "short",
day: "numeric",
hour: "numeric",
minute: "numeric",
second: "numeric",
});

await sendDiscordWebhook(DISCORD_WEBHOOK_URL_ACCESS_LOG, {
content: `[${c.req.method}] ${info.remote.address} ${c.req.url}`,
content: c.req.path,
embeds: [
{
description: `[${c.req.method}] ${c.req.url}`,
color: 0x008000,
footer: {
text: `${time} - ${info.remote.address}`,
},
},
],
});
};

Expand Down Expand Up @@ -53,7 +72,7 @@ export const sendAPIAccessLog = async (
{
title,
description: `[${c.req.method}] ${c.req.url}`,
color: error ? 0xff0000 : 0x20c030,
color: error ? 0xff0000 : 0x008000,
fields: [{
name: "Hashed API Key",
value: hashedApiKey,
Expand Down

0 comments on commit 819dbb9

Please sign in to comment.