Initial commit
This commit is contained in:
19
src/helpers/logging.ts
Normal file
19
src/helpers/logging.ts
Normal file
@ -0,0 +1,19 @@
|
||||
import { Middleware } from "grammy";
|
||||
import type { Update } from "@grammyjs/types";
|
||||
import type { Context } from "#root/context.js";
|
||||
|
||||
export function getUpdateInfo(ctx: Context): Omit<Update, "update_id"> {
|
||||
const { update_id, ...update } = ctx.update;
|
||||
return update;
|
||||
}
|
||||
|
||||
export function logHandle(id: string): Middleware<Context> {
|
||||
return (ctx, next) => {
|
||||
ctx.logger.info({
|
||||
msg: `handle ${id}`,
|
||||
...(id.startsWith("unhandled") ? { update: getUpdateInfo(ctx) } : {}),
|
||||
});
|
||||
|
||||
return next();
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user