Skip to content

Commit 57f0435

Browse files
author
daniel.mueller
committed
add logging and debug info
1 parent eaf091c commit 57f0435

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

mailpie.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ type errorState struct {
3737
}
3838

3939
func main() {
40+
logrus.SetLevel(logrus.DebugLevel)
4041
errorChannel := make(chan errorState)
4142
go serveSPA(errorChannel)
4243
go serveSSE(errorChannel)
@@ -72,7 +73,10 @@ func serveSMTP(errorChannel chan errorState) {
7273
AuthHandler: func(remoteAddr net.Addr, mechanism string, username []byte, password []byte, shared []byte) (bool, error) {
7374
return true, nil
7475
},
75-
AuthMechs: map[string]bool{"PLAIN": true, "LOGIN": true},
76+
LogWrite: func(remoteIP, verb, line string) {
77+
logrus.WithField("ip", remoteIP).WithField("verb", verb).Debug(line)
78+
},
79+
AuthMechs: map[string]bool{"PLAIN": true, "LOGIN": true, "CRAM-MD5": false},
7680
}
7781
logrus.WithField("Address", addr).Info("Starting SMTP server")
7882
err := srv.ListenAndServe()
@@ -144,7 +148,8 @@ func serveSSE(errorChannel chan errorState) {
144148
func serveIMAP(errorChannel chan errorState) {
145149
be := imap.NewBackend()
146150
s := server.New(be)
147-
s.Debug = os.Stdout
151+
imapLogger := logrus.New()
152+
s.Debug = imapLogger.Writer()
148153
s.Addr = listenOnAddress + ":1143"
149154
s.AllowInsecureAuth = true
150155
logrus.WithField("Address", s.Addr).Info("Starting IMAP server")

pkg/event/events.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package event
22

3+
import "github.com/sirupsen/logrus"
4+
35
type Handler func(dispatcher string, data interface{})
46

57
type MessageQueue struct {
@@ -18,6 +20,7 @@ func NewOrGet() *MessageQueue {
1820
}
1921

2022
func (mq MessageQueue) Dispatch(event string, from string, data interface{}) {
23+
logrus.WithFields(map[string]interface{}{"event": event, "from": from}).Debug("New Event Dispatched")
2124
subscriber, ok := mq.topics[event]
2225
if !ok {
2326
return

0 commit comments

Comments
 (0)