Skip to content

Commit 42eb015

Browse files
committed
Improve logging
1 parent 74a4b54 commit 42eb015

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

src/bot/helpers/logging.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export function getUpdateInfo(ctx: Context): Omit<Update, "update_id"> {
1212
export function logHandle(id: string): Middleware<Context> {
1313
return (ctx, next) => {
1414
ctx.logger.info({
15-
msg: `handle ${id}`,
15+
msg: `Handle "${id}"`,
1616
...(id.startsWith("unhandled") ? { update: getUpdateInfo(ctx) } : {}),
1717
});
1818

src/bot/middlewares/update-logger.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export function updateLogger(): Middleware<Context> {
77
return async (ctx, next) => {
88
ctx.api.config.use((previous, method, payload, signal) => {
99
ctx.logger.debug({
10-
msg: "bot api call",
10+
msg: "Bot API call",
1111
method,
1212
payload,
1313
});
@@ -16,7 +16,7 @@ export function updateLogger(): Middleware<Context> {
1616
});
1717

1818
ctx.logger.debug({
19-
msg: "update received",
19+
msg: "Update received",
2020
update: getUpdateInfo(ctx),
2121
});
2222

@@ -26,8 +26,8 @@ export function updateLogger(): Middleware<Context> {
2626
} finally {
2727
const endTime = performance.now();
2828
ctx.logger.debug({
29-
msg: "update processed",
30-
duration: endTime - startTime,
29+
msg: "Update processed",
30+
elapsed: endTime - startTime,
3131
});
3232
}
3333
};

src/main.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ try {
1313

1414
// graceful shutdown
1515
onShutdown(async () => {
16-
logger.info("shutdown");
16+
logger.info("Shutdown");
1717

1818
await bot.stop();
1919
});
@@ -47,12 +47,16 @@ try {
4747
allowed_updates: config.BOT_ALLOWED_UPDATES,
4848
secret_token: config.BOT_WEBHOOK_SECRET,
4949
});
50+
logger.info({
51+
msg: "Webhook was set",
52+
url: config.BOT_WEBHOOK,
53+
});
5054
} else if (config.BOT_MODE === "polling") {
5155
await bot.start({
5256
allowed_updates: config.BOT_ALLOWED_UPDATES,
5357
onStart: ({ username }) =>
5458
logger.info({
55-
msg: "bot running...",
59+
msg: "Bot running...",
5660
username,
5761
}),
5862
});

0 commit comments

Comments
 (0)