Replies: 2 comments
-
|
There's no built-in way to label logs per auxiliary worker right now. Miniflare/workerd doesn't tag Easiest workaround — create a tagged logger in each worker: // In your main worker
const log = (...args: unknown[]) => console.log('[main]', ...args);
// In each auxiliary worker
const log = (...args: unknown[]) => console.log('[auth-worker]', ...args);If you want something less manual, wrap const WORKER_NAME = 'auth-worker'; // or derive from import.meta.url
const originalConsole = { ...console };
for (const method of ['log', 'warn', 'error', 'info', 'debug'] as const) {
console[method] = (...args: unknown[]) => originalConsole[method](`[${WORKER_NAME}]`, ...args);
}This is admittedly not great compared to |
Beta Was this translation helpful? Give feedback.
-
|
Confirming what @mg1986jp said — no built-in flag for this. The vite-plugin runs all the workers in one workerd process and Cleanest workaround I've found is monkey-patching console at the top of each worker so you don't have to touch every log call: // src/main.ts (and similarly in each aux worker)
const TAG = '[main]'; // or [auth], [api], etc.
for (const m of ['log', 'warn', 'error', 'info', 'debug'] as const) {
const orig = console[m].bind(console);
console[m] = (...args: unknown[]) => orig(TAG, ...args);
}One-time setup per worker, all logs auto-tagged after that. Works for transitive ones too (deps that call If this is something you'd want first-class in the plugin it'd probably want raising as a feature request on workers-sdk — feels like a reasonable miniflare-level addition (it already names workers in its config). |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I've just upgraded to Astro 6 and I'm using the Vite plugin to load in
auxiliaryWorkers. This is all working well.The problem is that all of the
console.log()statements end up output to the same place with no indication of which worker they're coming from, so the logs are all mixed together. I misswrangler devtelling me which worker the logs are coming from in the console.Is there a way to enable logs from the auxiliary workers to be output to the terminal with the worker name?
Beta Was this translation helpful? Give feedback.
All reactions