This commit is contained in:
2026-02-04 12:51:41 +00:00
parent 4fdbfb0fb3
commit f1e13f87f6
19 changed files with 722 additions and 67 deletions

32
convex/logs.ts Normal file
View File

@@ -0,0 +1,32 @@
import { mutation } from "./_generated/server";
import { v } from "convex/values";
import { getAuthUserId } from "@convex-dev/auth/server";
export const createLog = mutation({
args: {
level: v.union(
v.literal("debug"),
v.literal("info"),
v.literal("warn"),
v.literal("error")
),
message: v.string(),
labels: v.array(v.string()),
payload: v.optional(v.any()),
source: v.optional(v.string()),
requestId: v.optional(v.string()),
projectId: v.optional(v.id("projects")),
},
handler: async (ctx, args) => {
const userId = await getAuthUserId(ctx);
const base = {
...args,
createdAt: Date.now(),
};
if (userId) {
await ctx.db.insert("logs", { ...base, userId });
return;
}
await ctx.db.insert("logs", base);
},
});