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:
- Parent terms lookup:
parent terms found with the name %name... - Fields detected from source:
fields detected from xml: %fieldlist - 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
- Install and enable taxonomy_import module
- Enable dblog module
- Import a CSV file with 10+ terms into any vocabulary
- Navigate to /admin/reports/dblog or run
drush ws --type=taxonomy_import - 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:
- Add a boolean config property
debug_modeto the module's config schema (default: false) - 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