Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement SMTP client debug logging #102

Merged
merged 3 commits into from
Jan 14, 2023
Merged

Conversation

wneessen
Copy link
Owner

Resolves #101.

Since we now have full control over the SMTP client we can also access the message input and output.

This PR introduces a new debug logging feature. Via the Client.WithDebugLog the user can enable this feature. It will then make use of the new smtp/Client.SetDebugLog method. Once the flag is set to true, the SMTP client will start logging incoming and outgoing messages to os.Stderr.

Log directions will be logged accordingly.

  • C --> S means Client to Server communication
  • C <-- S means Server to Client communication

Example:
image

Resolves #101.

Since we now have full control over the SMTP client we can also access the message input and output.

This PR introduces a new debug logging feature. Via the `Client.WithDebugLog` the user can enable this feature. It will then make use of the new `smtp/Client.SetDebugLog` method. Once the flag is set to true, the SMTP client will start logging incoming and outgoing messages to os.Stderr.

Log directions will be output accordingly
We don't want to expose SMTP authentication details in tests, therefore the tests have been adjusted a bit
@wneessen wneessen linked an issue Jan 14, 2023 that may be closed by this pull request
@codecov-commenter
Copy link

Codecov Report

Merging #102 (ccbab59) into main (813020f) will decrease coverage by 0.27%.
The diff coverage is 64.51%.

@@            Coverage Diff             @@
##             main     #102      +/-   ##
==========================================
- Coverage   81.05%   80.78%   -0.28%     
==========================================
  Files          20       20              
  Lines        1837     1868      +31     
==========================================
+ Hits         1489     1509      +20     
- Misses        249      258       +9     
- Partials       99      101       +2     
Impacted Files Coverage Δ
smtp/smtp.go 63.92% <55.55%> (-0.64%) ⬇️
client.go 78.85% <76.92%> (-0.08%) ⬇️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@wneessen wneessen merged commit f3039cd into main Jan 14, 2023
@wneessen wneessen deleted the 101-client-debug-logging branch January 14, 2023 12:18
@lightglitch
Copy link

Instead of using the golang logger with not use an interface for the logger like for example:

type Logger interface {
	Errorf(format string, v ...interface{})
	Warnf(format string, v ...interface{})
	Debugf(format string, v ...interface{})
}

with mail.WithDebugLog(log) so that we can plug any logger that we want into the library?

@wneessen
Copy link
Owner Author

wneessen commented Feb 1, 2023

Good point. I'll check what would be the best option here.

wneessen added a commit that referenced this pull request Feb 3, 2023
As stated in #102 (comment) it would be beneficial if, instead of forcing the Go stdlib logger on the user to provide a simple interface and use that for logging purposes.

This PR implements this simple log.Logger interface as well as a standard logger that satisfies this interface. If no custom logger is provided, the Stdlog will be used (which makes use of the Go stdlib again).

Accordingly, a `Client.WithLogger` and `Client.SetLogger` have been implemented. Same applies for the smtp counterparts.
desdeel2d0m added a commit to desdeel2d0m/go-mail that referenced this pull request Jul 1, 2024
As stated in wneessen/go-mail#102 (comment) it would be beneficial if, instead of forcing the Go stdlib logger on the user to provide a simple interface and use that for logging purposes.

This PR implements this simple log.Logger interface as well as a standard logger that satisfies this interface. If no custom logger is provided, the Stdlog will be used (which makes use of the Go stdlib again).

Accordingly, a `Client.WithLogger` and `Client.SetLogger` have been implemented. Same applies for the smtp counterparts.
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.

Client debug logging
3 participants