Skip to content

feat: add configurable log levels via env.logLevel#1507

Open
taronsung wants to merge 7 commits intohuggingface:v4from
taronsung:feat/logging-levels-117
Open

feat: add configurable log levels via env.logLevel#1507
taronsung wants to merge 7 commits intohuggingface:v4from
taronsung:feat/logging-levels-117

Conversation

@taronsung
Copy link

Summary

Adds configurable logging levels to control library verbosity, as requested in #117.

Changes

  • Add LogLevel enum with NONE, ERROR, WARNING, INFO, DEBUG levels
  • Add env.logLevel configuration (defaults to WARNING)
  • Create logger utility that respects the configured log level
  • Update console.log/warn calls in pipelines.js to use logger
  • Export LogLevel and logger from main entry point

Usage

import { env, LogLevel, logger } from '@huggingface/transformers';

// Set log level to suppress all logs
env.logLevel = LogLevel.NONE;

// Set log level to show only errors
env.logLevel = LogLevel.ERROR;

// Set log level to show warnings and above (default)
env.logLevel = LogLevel.WARNING;

// Set log level to show info messages and above
env.logLevel = LogLevel.INFO;

// Set log level to show all messages including debug
env.logLevel = LogLevel.DEBUG;

// Use the logger directly
logger.info('Model loaded successfully');
logger.warn('Deprecated method used');
logger.error('Failed to load model');
logger.debug('Token count:', tokens.length);

Notes

  • This PR focuses on the infrastructure and updates pipelines.js as a starting point
  • Other files with console.warn/error calls can be migrated in follow-up PRs
  • The TextStreamer output in streamers.js was intentionally not changed as it's user-facing streaming output, not logging

Closes #117

@xenova
Copy link
Collaborator

xenova commented Jan 30, 2026

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 packages/transformers folder... all else should stay mostly similar.

We could also take inspiration from the python transformers library... maybe implementing methods like warning_once (for example) to only log once in case of repeated calls. WDYT? Edit: Actually, maybe not worth it because browser runtimes typically collapse duplicate logs anyway.

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
@taronsung taronsung force-pushed the feat/logging-levels-117 branch from 58097d9 to af0f0d4 Compare January 30, 2026 22:34
@taronsung taronsung changed the base branch from main to v4 January 30, 2026 22:34
Copy link
Collaborator

@nico-martin nico-martin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

// Environment variables
export { env } from './env.js';
export { env, LogLevel } from './env.js';
export { logger } from './utils/logger.js';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason you want to export the logger? In my opinion that should stay in the library and should not be user facing.

@HuggingFaceDocBuilderDev

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature request] Logging Level and Progress Bar for Model Downloads

4 participants