diff options
-rw-r--r-- | cmd/koushin/main.go | 7 | ||||
-rw-r--r-- | docs/cli.md | 2 | ||||
-rw-r--r-- | server.go | 3 | ||||
-rw-r--r-- | session.go | 9 |
4 files changed, 18 insertions, 3 deletions
diff --git a/cmd/koushin/main.go b/cmd/koushin/main.go index afdf7f3..392150f 100644 --- a/cmd/koushin/main.go +++ b/cmd/koushin/main.go @@ -23,9 +23,10 @@ func main() { var addr string flag.StringVar(&options.Theme, "theme", "", "default theme") flag.StringVar(&addr, "addr", ":1323", "listening address") + flag.BoolVar(&options.Debug, "debug", false, "enable debug logs") flag.Usage = func() { - fmt.Fprintf(flag.CommandLine.Output(), "usage: koushin [options...] <upstream server...>\n") + fmt.Fprintf(flag.CommandLine.Output(), "usage: koushin [options...] <upstream servers...>\n") flag.PrintDefaults() } @@ -48,6 +49,10 @@ func main() { } e.Use(middleware.Recover()) + if options.Debug { + e.Logger.SetLevel(log.DEBUG) + } + sigs := make(chan os.Signal, 1) signal.Notify(sigs, syscall.SIGUSR1) go func() { diff --git a/docs/cli.md b/docs/cli.md index 36964e9..c3bae3f 100644 --- a/docs/cli.md +++ b/docs/cli.md @@ -33,6 +33,8 @@ The following URL schemes are supported: **-addr**: listening address (default: ":1323") +**-debug**: enable debug logs and print IMAP network activity + **-h**, **--help**: show help message and exit # SIGNALS @@ -59,7 +59,7 @@ func newServer(e *echo.Echo, options *Options) (*Server, error) { return nil, err } - s.Sessions = newSessionManager(s.dialIMAP, s.dialSMTP, e.Logger) + s.Sessions = newSessionManager(s.dialIMAP, s.dialSMTP, e.Logger, options.Debug) return s, nil } @@ -283,6 +283,7 @@ func handleUnauthenticated(next echo.HandlerFunc, ctx *Context) error { type Options struct { Upstreams []string Theme string + Debug bool } // New creates a new server. @@ -6,6 +6,7 @@ import ( "errors" "fmt" "net/http" + "os" "sync" "time" @@ -142,17 +143,19 @@ type SessionManager struct { dialIMAP DialIMAPFunc dialSMTP DialSMTPFunc logger echo.Logger + debug bool locker sync.Mutex sessions map[string]*Session // protected by locker } -func newSessionManager(dialIMAP DialIMAPFunc, dialSMTP DialSMTPFunc, logger echo.Logger) *SessionManager { +func newSessionManager(dialIMAP DialIMAPFunc, dialSMTP DialSMTPFunc, logger echo.Logger, debug bool) *SessionManager { return &SessionManager{ sessions: make(map[string]*Session), dialIMAP: dialIMAP, dialSMTP: dialSMTP, logger: logger, + debug: debug, } } @@ -167,6 +170,10 @@ func (sm *SessionManager) connectIMAP(username, password string) (*imapclient.Cl return nil, AuthError{err} } + if sm.debug { + c.SetDebug(os.Stderr) + } + return c, nil } |