feat: add configurable log levels via env.logLevel#1507
feat: add configurable log levels via env.logLevel#1507xenova merged 13 commits intohuggingface:mainfrom
Conversation
|
Hi @taronsung 👋 Thanks for the PR! I do like this feature, and it's definitely something I think we can implement. Since we're in the process of a relatively large refactor (v4: https://github.com/huggingface/transformers.js/tree/v4), could you update the base to be that branch? From the looks of it, it'd just entail moving the new files into the We could also take inspiration from the python transformers library... maybe implementing methods like |
Add LogLevel enum and env.logLevel configuration to control library verbosity. Create logger utility that respects the configured log level. Replace console.log/warn calls in pipelines with logger methods. Rebased onto v4 branch and moved files to packages/transformers folder. Closes huggingface#117
58097d9 to
af0f0d4
Compare
nico-martin
left a comment
There was a problem hiding this comment.
I added some commits to the PR. Most of it is just more console. that I wanted to replace with logger., but I also added a mapping between our own logLevels and the ONNX_ENV.logLevel.
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
|
main comment is here; next, for some reason I'm unable to merge main into this branch. @taronsung could you rebase? alternatively, @nico-martin if you have permission, could you ensure the PR is on latest main? thanks! |
|
@xenova, I merged origin/main into this branch so its now up to date with main. Imo its ready to be merged :D |
| // Set default log level, but allow overriding through session options | ||
| logSeverityLevel: DEFAULT_LOG_LEVEL, | ||
| // Set default log severity level, but allow overriding through session options | ||
| logSeverityLevel: getOnnxLogSeverityLevel(env.logLevel ?? 30), |
There was a problem hiding this comment.
We might as well use our own log level dict and then use LogLevel.WARNING here (instead of a magic number)
| /** @type {import('onnxruntime-common').Env} */ | ||
| const ONNX_ENV = ONNX?.env; | ||
| ONNX_ENV.logLevel = LOG_LEVELS[DEFAULT_LOG_LEVEL]; | ||
| ONNX_ENV.logLevel = ONNX_LOG_LEVEL_NAMES[getOnnxLogSeverityLevel(env.logLevel ?? 30)]; |
|
Just saw this PR. I need to mention that Also, if setting A little bit confusing but need to be careful for this part. @xenova |
|
Thanks for the info @fs-eire 👍 Do you have any suggestions to improve this? Luckily it shouldn't affect most users, and the default we have chosen are much better than what they used to be (outputting far too many logs). This is similar to a problem I described to @nico-martin, which makes session-level settings a bit more difficult to implement (since ORT uses global settings for many things, like proxying). Ref: #1479 |
|
based on the current limitation, we probably have something a "production" mode and a "diagnose" mode, where in production mode we can set ORT env log level to error, and in diagnose mode we set ORT env log level to verbose (a little bit slower but it's fine since it's diagnose mode). This should match most users' expectation. |
|
It's not ideal, but I think it's quite rare for ORT variables to be changed by the user. TLDR: I can live with certain global dependencies that we cannot eliminate for good reasons. :D |
* feat: add configurable log levels via env.logLevel Add LogLevel enum and env.logLevel configuration to control library verbosity. Create logger utility that respects the configured log level. Replace console.log/warn calls in pipelines with logger methods. Rebased onto v4 branch and moved files to packages/transformers folder. Closes huggingface#117 * added logger to backends/onnx.js * added mapping from logLevel to ONNX Runtime log level * replaced console.log with logger * fixed doc builder * improved jsdoc for logLevel * removed .venv folder * removed logger export * changed how log levels are handled * 30 to LogLevel.WARNING * 30 to LogLevel.WARNING * Remove old comments --------- Co-authored-by: Nico Martin <mail@nico.dev> Co-authored-by: Joshua Lochner <admin@xenova.com>
Summary
Adds configurable logging levels to control library verbosity, as requested in #117.
Changes
LogLevelenum with NONE, ERROR, WARNING, INFO, DEBUG levelsenv.logLevelconfiguration (defaults to WARNING)loggerutility that respects the configured log levelconsole.log/warncalls inpipelines.jsto useloggerLogLevelandloggerfrom main entry pointUsage
Notes
pipelines.jsas a starting pointconsole.warn/errorcalls can be migrated in follow-up PRsTextStreameroutput instreamers.jswas intentionally not changed as it's user-facing streaming output, not loggingCloses #117