`void/log`: add `logger.child(fields)` to bind fields to every line
Maintainer thường phản hồi trong vòng 1 ngày
@Dazzanova đang làm issue này rồi.
Từ ngày 27/10/2026.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 82/100
- Loại issue
- Tính năng
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- typescript
- Lĩnh vực
- backend
Hướng nghiên cứu
Start with void/src/runtime/log.ts and the existing format() try block to see how fields are copied and filtered. Then read test/unit/runtime-log.test.ts and add coverage for bound fields, overrides, nested children, and throwing getters; update the Logging methods line in docs/reference/api/resources.md with a one-line example. Done when the requested behaviors pass and logging still returns the safe line for throwing getters.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Summary
Apps usually tag every log line from a module with the same fields (component, queue, job), so the lines can be filtered in Workers Logs and with void project logs --filter. void/log has no way to bind those fields, so each call repeats them, or each app writes its own wrapper. The obvious wrapper breaks the logger's guarantee that it never throws.
The wrapper apps write today
import { logger as baseLogger } from 'void/log';
type Fields = Record<string, unknown>;
export const logger = {
...baseLogger,
child: (bound: Fields) => ({
error: (msg: string, fields?: Fields) => baseLogger.error(msg, { ...bound, ...fields }),
warn: (msg: string, fields?: Fields) => baseLogger.warn(msg, { ...bound, ...fields }),
info: (msg: string, fields?: Fields) => baseLogger.info(msg, { ...bound, ...fields }),
}),
};
The spread { ...bound, ...fields } runs before format(). That means it runs outside the try that makes logging safe. A field whose getter throws makes the base logger fall back to its safe line, but the wrapper throws the error into the caller instead ([email protected]; format() on main has the same try):
const fields = Object.defineProperty({}, 'boom', {
enumerable: true,
get() {
throw new Error('getter');
},
});
logger.info('base.ok', fields);
// {"msg":"base.ok","error":"log: fields not serializable"}
logger.child({ component: 'x' }).info('child.call', fields);
// throws Error: getter
A log call inside a catch or a queue consumer can then throw where it was meant to only record. Supporting this in void/log means each app no longer copies the wrapper, and the merge stays inside the guarantee.
Proposal
import { logger } from 'void/log';
const log = logger.child({ component: 'queue', queue: 'tasks' });
log.warn('task.retry', { taskId, attempt: 2 });
// {"msg":"task.retry","component":"queue","queue":"tasks","taskId":"…","attempt":2}
logger.child(fields)returns a logger witherror,warn,infoandchild.- Lines keep the
{ msg, ...fields }shape, so Cloudflare Tail capture and platform log filtering don't change. - Fields passed in a call override bound fields with the same name.
child()can be nested:log.child({ taskId })adds to the fields already bound.- Bound fields get the same handling as call fields.
msg,toJSON,__proto__andconstructorare skipped, functions are dropped, andErrorvalues are serialized (#583). - Logging never throws, including when bound or call fields have throwing getters.
Implementation
In packages/void/src/runtime/log.ts, build each logger from a bound object and have format(message, bound, fields) copy both inside the existing try. Bound fields are copied first, then call fields, using the same key filters. logger stays the root, with no bound fields, so existing calls behave the same.
Tests in packages/void/test/unit/runtime-log.test.ts:
- bound fields appear on every level
- call fields override bound fields
- nested
child()merges fields - reserved keys and functions in bound fields are skipped
- a throwing getter in bound or call fields falls back to the safe line instead of throwing
Docs: add logger.child(fields) to the methods line under Logging in docs/reference/api/resources.md, with a one-line example.
- Ngôn ngữ chính
- TypeScript
- Star
- 580
- Fork
- 56
- Merge trung bình
- 11 giờ 28 phút
- Pull request đã merge (30 ngày)
- 150
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của voidzero-dev/void
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
voidzero-dev/void#619 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
voidzero-dev/void#606 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
@void/react: client environment has no optimizeDeps.entries for pages, causing a dev re-optimization reload on first loadCó thể đã có người làm @0froq đã nhận hôm nay. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 66/100
voidzero-dev/void#599 · 1 bình luận · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 56/100
voidzero-dev/void#579 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 55/100
voidzero-dev/void#573 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của voidzero-dev/void
Issue tương tự
-
Plugin: sheet music can't be scrolled by hand before playbackCó thể đã có người làm @snakajima đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
receptron/jinglescript#51 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
Maintainer thường phản hồi trong vòng 9 ngày
-
clawsweeper:needs-maintainer-review clawsweeper:needs-product-decision clawsweeper:no-new-fix-pr clawsweeper:source-repro impact:ux-friction issue-rating: 🦞 diamond lobster P3
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
openclaw/openclaw#186424 · 1 bình luận · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
chore(worker): five module header comments describe the code from before later issues changed itĐang mởarea:dev U2-later
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
bentleypark/aiwatch#1824 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Pal-AI-Lab/Coopanion#469 ·
Maintainer thường phản hồi trong vòng 1 ngày