Problem/Motivation

The TaxonomyImport module writes WATCHDOG_DEBUG severity messages to the watchdog table during normal import operations. This fills the dblog table with unnecessary entries in production
environments and makes it difficult to monitor actual errors.

The problematic calls are in src/Service/TaxonomyUtils.php, method saveTerms(). Three separate debug() calls are made for every row being imported:

  1. Parent terms lookup: parent terms found with the name %name...
  2. Fields detected from source: fields detected from xml: %fieldlist
  3. Custom fields matching: custom fields not in Drupal... / custom fields matched in Drupal...

In a CSV import with 200 rows, this generates 600+ debug log entries. There is no configuration flag to disable this behavior, and there is no mechanism to differentiate development from
production logging.

Steps to reproduce

  1. Install and enable taxonomy_import module
  2. Enable dblog module
  3. Import a CSV file with 10+ terms into any vocabulary
  4. Navigate to /admin/reports/dblog or run drush ws --type=taxonomy_import
  5. Observe multiple DEBUG severity entries per import row

Expected: No debug messages written during normal operation.
Actual: 3 debug entries per imported row.

Proposed resolution

Add a configuration flag to the module's settings that toggles debug logging on/off. The change requires:

  1. Add a boolean config property debug_mode to the module's config schema (default: false)
  2. Wrap the three debug() calls in TaxonomyUtils::saveTerms() with a conditional check

File: src/Service/TaxonomyUtils.php

Add property and constructor injection:

   protected bool $debugMode = FALSE;

   public function __construct(EntityTypeManagerInterface $entityTypeManager, ConfigFactoryInterface $configFactory) {
     $this->entityTypeManager = $entityTypeManager;
     $this->debugMode = $configFactory->get('taxonomy_import.settings')->get('debug_mode') ?? FALSE;
   }

   public function isDebugEnabled(): bool {
     return $this->debugMode;
   }
   

Wrap the three debug calls:

   if ($this->isDebugEnabled()) {
     \Drupal::logger('taxonomy_import')->debug('parent terms found with the name %name...', [...]);
   }
   
   if ($this->isDebugEnabled()) {
     \Drupal::logger('taxonomy_import')->debug('fields detected from xml: %fieldlist...', [...]);
   }
   
   if ($this->isDebugEnabled()) {
     \Drupal::logger('taxonomy_import')->debug('custom fields not in Drupal...', [...]);
   }
   

File: config/schema/taxonomy_import.schema.yml

   taxonomy_import.settings:
     type: config_object
     label: 'Taxonomy Import settings'
     mapping:
       debug_mode:
         type: boolean
         label: 'Enable debug logging'
   

Remaining tasks

  • [ ] Confirm the bug can be reproduced
  • [ ] Add config schema for debug_mode setting
  • [ ] Update TaxonomyUtils constructor to inject ConfigFactoryInterface
  • [ ] Wrap the three debug() calls with isDebugEnabled() check
  • [ ] Add configuration form or confirm existing settings page
  • [ ] Update module's services.yml to pass ConfigFactoryInterface
  • [ ] Write tests for debug toggle behavior

User interface changes

None or minimal. If the module has an existing settings form at /admin/config/taxonomy_import/settings, add a checkbox "Enable debug logging (for development only)" with description
warning about dblog pollution.

API changes

None. This is a new configuration property with a local effect on logging behavior.

Data model changes

None. Config-only change, no database schema modifications.

Comments

alekas created an issue.