2023-05-30 17:11:28 +00:00
|
|
|
// Copyright (C) 2019-2023 Nicola Murino
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published
|
|
|
|
// by the Free Software Foundation, version 3.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
package logger
|
|
|
|
|
2023-08-20 19:42:41 +00:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/wneessen/go-mail/log"
|
|
|
|
)
|
|
|
|
|
2023-05-30 17:11:28 +00:00
|
|
|
const (
|
|
|
|
mailLogSender = "smtpclient"
|
|
|
|
)
|
|
|
|
|
|
|
|
// MailAdapter is an adapter for mail.Logger
|
|
|
|
type MailAdapter struct {
|
|
|
|
ConnectionID string
|
|
|
|
}
|
|
|
|
|
|
|
|
// Errorf emits a log at Error level
|
2023-08-20 19:42:41 +00:00
|
|
|
func (l *MailAdapter) Errorf(logMsg log.Log) {
|
|
|
|
format := l.getFormatString(&logMsg)
|
|
|
|
ErrorToConsole(format, logMsg.Messages...)
|
|
|
|
Log(LevelError, mailLogSender, l.ConnectionID, format, logMsg.Messages...)
|
2023-05-30 17:11:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Warnf emits a log at Warn level
|
2023-08-20 19:42:41 +00:00
|
|
|
func (l *MailAdapter) Warnf(logMsg log.Log) {
|
|
|
|
format := l.getFormatString(&logMsg)
|
|
|
|
WarnToConsole(format, logMsg.Messages...)
|
|
|
|
Log(LevelWarn, mailLogSender, l.ConnectionID, format, logMsg.Messages...)
|
2023-05-30 17:11:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Infof emits a log at Info level
|
2023-08-20 19:42:41 +00:00
|
|
|
func (l *MailAdapter) Infof(logMsg log.Log) {
|
|
|
|
format := l.getFormatString(&logMsg)
|
|
|
|
InfoToConsole(format, logMsg.Messages...)
|
|
|
|
Log(LevelInfo, mailLogSender, l.ConnectionID, format, logMsg.Messages...)
|
2023-05-30 17:11:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Debugf emits a log at Debug level
|
2023-08-20 19:42:41 +00:00
|
|
|
func (l *MailAdapter) Debugf(logMsg log.Log) {
|
|
|
|
format := l.getFormatString(&logMsg)
|
|
|
|
DebugToConsole(format, logMsg.Messages...)
|
|
|
|
Log(LevelDebug, mailLogSender, l.ConnectionID, format, logMsg.Messages...)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (*MailAdapter) getFormatString(logMsg *log.Log) string {
|
|
|
|
p := "C <-- S:"
|
|
|
|
if logMsg.Direction == log.DirClientToServer {
|
|
|
|
p = "C --> S:"
|
|
|
|
}
|
|
|
|
return fmt.Sprintf("%s %s", p, logMsg.Format)
|
2023-05-30 17:11:28 +00:00
|
|
|
}
|