fix(core): respect log level in worker threads - #1058
Conversation
The log level set by `--log-level` was only applied on the main thread. Worker threads load their own module graph, so the default logger export creates a separate instance there that keeps the default `info` level. Warnings emitted from inside workers were therefore printed regardless of the requested level. Pass the level through Piscina `workerData` and apply it at the worker entry point. This adds a `getLogLevel()` accessor, as there was no way to read the configured level back. Fixes: nodejs#1032 Signed-off-by: Avocado <ujubongbong@gmail.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
could you add some test |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1058 +/- ##
=======================================
Coverage 89.67% 89.67%
=======================================
Files 205 205
Lines 19208 19224 +16
Branches 1795 1795
=======================================
+ Hits 17224 17240 +16
Misses 1976 1976
Partials 8 8 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
| File | Main | PR | Change |
|---|---|---|---|
orama-db.json |
9.18 MB | 9.18 MB | +1.15 KB (+0.0%) |
Performance estimate (single CI run)
- Generation time: 1.6% slower (8.32 s → 8.45 s)
- Peak memory: 4.6% higher (1.80 GB → 1.89 GB)
web Generator
Performance estimate (single CI run)
- Generation time: 23.4% faster (87.03 s → 66.68 s)
- Peak memory: 2.1% higher (4.74 GB → 4.84 GB)
Assert that the pool forwards the current level through `workerData` and that a worker actually applies it, using a fixture generator that reports the level it sees. Removing the fix makes both fail, while the default level case keeps passing. Also cover the new `getLogLevel()` accessor. Signed-off-by: Avocado <ujubongbong@gmail.com>
|
@AugustinMauroy Added tests.
I checked that they actually catch this: reverting the |
What
--log-levelhad no effect on warnings coming from worker threads.printed 81
WARNlines instead of none.Why
The level is applied on the main thread only. Worker threads load their own module graph, so the default logger export creates a separate instance there that keeps the default
infolevel. The warnings in the report come fromresolveTypes.mjs, which runs inside the workers.The same input makes it clear:
--log-level fataldoc/api/)Both inputs produce warnings, but only the single file respects the requested level.
parallel.mjsskips the pool whenthreads <= 1 || items.length <= 2, so running the directory with--threads 1silences the warnings as well.How
The level is passed through Piscina
workerDataand applied at the worker entry point. This adds a smallgetLogLevel()accessor, as there was no way to read the configured level back.I also considered putting the level into
configuration, which already reaches the workers, butcreateTaskdeliberately narrows what it sends:Sending the level that way would repeat it for every chunk, while
workerDatais sent once per worker.Verification
--log-level fatalThe default level is unchanged, so nothing is silenced that should not be. Full suite passes (560 tests), lint and format checks are clean.
Fixes: #1032