Problem / Motivation

When a site sends a large volume of emails (for example, newsletters to thousands of subscribers), the SMTP module
currently creates an individual log entry for every recipient. This produces excessive log noise on most production
sites and makes it harder to surface real errors or warnings.

Site owners and developers need a configurable logging verbosity that follows Drupal's / PSR-3 log levels
(debug, info, notice, warning, error,
critical, etc.). Dedicated mail-log modules already exist for projects that require detailed
per-message tracking; the SMTP module should default to a reasonable level of verbosity and allow administrators to
choose a different level.

Steps to reproduce

  1. Send a bulk mailing through the SMTP module (e.g., a newsletter to several thousand users).
  2. Visit Reports → Recent log messages and filter on the SMTP logger.
  3. Observe one entry per recipient at the current (too-verbose) log level.

Proposed resolution

Add a configuration setting to the SMTP module that selects the minimum PSR-3/Drupal log level at which SMTP events
are written. The setting should live at /admin/config/system/smtp and present the standard PSR-3 levels
as options. The module should only write per-message log entries when the configured log level is equal to or more
verbose than the level assigned to that event.

Suggested default: warning (so that routine successful sends are not logged, but warnings/errors still
are). Administrators who need per-message traces can set the level to info or debug, or
install a dedicated mail logging module for full message auditing.

User interface changes

  • Add a new setting to /admin/config/system/smtp:
    (In a Drupal config form this would be a #type => 'select' with \Psr\Log\LogLevel
    constants as values.)
  • Add explanatory help text: "Select the minimum log level at which SMTP events are recorded. Use
    debug or info for per-message logging; warning or higher
    is recommended for production."

API changes

  • No public API changes required. Internally, use the configured log level when writing messages.
  • Example code (inside the SMTP send routine) that respects the configured level:

Data model changes

No persistent data-model changes required. This is a configuration change only (e.g.,
smtp.settings:log_level).

Remaining tasks

  • Add the config form element to the SMTP config form and save to config.
  • Implement a robust level-comparison helper (map PSR-3 names to numeric severities) and unit tests.
  • Replace direct calls that write per-message log entries with the conditional logging approach above.
  • Update README and module docs to document the new setting and recommended production default.
  • Consider a follow-up feature: an option to log only failures (i.e., log on error+), or integration
    guidance for dedicated mail-audit modules.

This approach makes SMTP logging conform to PSR-3 / RFC-style log levels, reduces production noise by default, and
gives site administrators a straightforward way to request more (or less) verbosity when needed.

CommentFileSizeAuthor
#4 smtp_settings.png17.38 KBritarshi_chakraborty

Issue fork smtp-3556311

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

martin joergensen created an issue. See original summary.

ritarshi_chakraborty’s picture

Assigned: Unassigned » ritarshi_chakraborty

Working on it.

ritarshi_chakraborty’s picture

Assigned: ritarshi_chakraborty » Unassigned
Status: Active » Needs review
StatusFileSize
new17.38 KB
bluegeek9’s picture

Issue summary: View changes
Status: Needs review » Needs work

bluegeek9 changed the visibility of the branch 8.x-1.x to hidden.

bluegeek9 changed the visibility of the branch 3556311-limiting-logging to hidden.

bluegeek9’s picture

Assigned: Unassigned » bluegeek9
Status: Needs work » Active
Issue tags: -logging

bluegeek9’s picture

Assigned: bluegeek9 » Unassigned
Status: Active » Fixed
//www.flaticon.com/free-icons/thank-you Thank you for your contribution! Your continued support makes this project sustainable.
There are multiple ways to show appreciation for the work contributed to this project including:
  • Triage issues and adding more context to existing issues.
  • Flagging SMTP as a favorite on the project page to help others discover it and show your support.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.