aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRené 'Necoro' Neumann <necoro@necoro.eu>2020-04-25 21:24:34 +0200
committerRené 'Necoro' Neumann <necoro@necoro.eu>2020-04-25 21:24:34 +0200
commit92b3181672b62052d4193749cd02f4be7d91e2ee (patch)
treea7061ae56b986ca6d513439b0a54337e1bda9ca6
parente7acda5f2494d78f7bd41c4b7eff982f007a1b36 (diff)
downloadfeed2imap-go-92b3181672b62052d4193749cd02f4be7d91e2ee.tar.gz
feed2imap-go-92b3181672b62052d4193749cd02f4be7d91e2ee.tar.bz2
feed2imap-go-92b3181672b62052d4193749cd02f4be7d91e2ee.zip
Add debug output
-rw-r--r--main.go7
-rw-r--r--pkg/log/log.go40
2 files changed, 39 insertions, 8 deletions
diff --git a/main.go b/main.go
index 415d19f..026ef0a 100644
--- a/main.go
+++ b/main.go
@@ -16,6 +16,7 @@ import (
var cfgFile = flag.String("f", "config.yml", "configuration file")
var cacheFile = flag.String("c", "feed.cache", "cache file")
var verbose = flag.Bool("v", false, "enable verbose output")
+var debug = flag.Bool("d", false, "enable debug output")
func processFeed(feed *feed.Feed, cfg *config.Config, client *imap.Client, wg *sync.WaitGroup) {
defer wg.Done()
@@ -46,7 +47,11 @@ func processFeed(feed *feed.Feed, cfg *config.Config, client *imap.Client, wg *s
func run() error {
flag.Parse()
- log.SetDebug(*verbose)
+ if *debug {
+ log.SetDebug()
+ } else if *verbose {
+ log.SetVerbose()
+ }
log.Print("Starting up...")
diff --git a/pkg/log/log.go b/pkg/log/log.go
index 0238c7e..4c69c1c 100644
--- a/pkg/log/log.go
+++ b/pkg/log/log.go
@@ -7,26 +7,52 @@ import (
)
var debugLogger = log.New(os.Stdout, "", log.LstdFlags)
+var verboseLogger = log.New(os.Stdout, "", log.LstdFlags)
var errorLogger = log.New(os.Stderr, "ERROR ", log.LstdFlags|log.Lmsgprefix)
var warnLogger = log.New(os.Stdout, "WARN ", log.LstdFlags|log.Lmsgprefix)
-var enableDebug = false
-func SetDebug(state bool) {
- enableDebug = state
+type logLevel byte
+
+const (
+ debug logLevel = iota
+ info
+ warn
+)
+
+var level logLevel = warn
+
+func SetVerbose() {
+ level = info
}
-func Print(v ...interface{}) {
- if enableDebug {
+func SetDebug() {
+ level = debug
+}
+
+func Debug(v ...interface{}) {
+ if level <= debug {
_ = debugLogger.Output(2, fmt.Sprint(v...))
}
}
-func Printf(format string, v ...interface{}) {
- if enableDebug {
+func Debugf(format string, v ...interface{}) {
+ if level <= debug {
_ = debugLogger.Output(2, fmt.Sprintf(format, v...))
}
}
+func Print(v ...interface{}) {
+ if level <= info {
+ _ = verboseLogger.Output(2, fmt.Sprint(v...))
+ }
+}
+
+func Printf(format string, v ...interface{}) {
+ if level <= info {
+ _ = verboseLogger.Output(2, fmt.Sprintf(format, v...))
+ }
+}
+
func Error(v ...interface{}) {
_ = errorLogger.Output(2, fmt.Sprint(v...))
}