aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--internal/log/log.go46
-rw-r--r--internal/parse/parse.go5
-rw-r--r--internal/util/util.go17
-rw-r--r--main.go10
4 files changed, 54 insertions, 24 deletions
diff --git a/internal/log/log.go b/internal/log/log.go
new file mode 100644
index 0000000..d2c09d0
--- /dev/null
+++ b/internal/log/log.go
@@ -0,0 +1,46 @@
+package log
+
+import (
+ "fmt"
+ "log"
+ "os"
+)
+
+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
+}
+
+func Print(v ...interface{}) {
+ if !enableDebug {
+ _ = log.Output(2, fmt.Sprint(v...))
+ }
+}
+
+func Printf(format string, v ...interface{}) {
+ if !enableDebug {
+ _ = log.Output(2, fmt.Sprintf(format, v...))
+ }
+}
+
+func Error(v ...interface{}) {
+ _ = errorLogger.Output(2, fmt.Sprint(v...))
+}
+
+//noinspection GoUnusedExportedFunction
+func Errorf(format string, a ...interface{}) {
+ _ = errorLogger.Output(2, fmt.Sprintf(format, a...))
+}
+
+//noinspection GoUnusedExportedFunction
+func Warn(v ...interface{}) {
+ _ = warnLogger.Output(2, fmt.Sprint(v...))
+}
+
+//noinspection GoUnusedExportedFunction
+func Warnf(format string, a ...interface{}) {
+ _ = warnLogger.Output(2, fmt.Sprintf(format, a...))
+}
diff --git a/internal/parse/parse.go b/internal/parse/parse.go
index a4112d9..ddf1f0f 100644
--- a/internal/parse/parse.go
+++ b/internal/parse/parse.go
@@ -3,14 +3,13 @@ package parse
import (
ctxt "context"
"fmt"
- "log"
"sync"
"time"
"github.com/mmcdole/gofeed"
"github.com/Necoro/feed2imap-go/internal/config"
- "github.com/Necoro/feed2imap-go/internal/util"
+ "github.com/Necoro/feed2imap-go/internal/log"
)
func context() (ctxt.Context, ctxt.CancelFunc) {
@@ -33,7 +32,7 @@ func handleFeed(feed *config.Feed, wg *sync.WaitGroup) {
log.Printf("Fetching %s from %s", feed.Name, feed.Url)
if err := parseFeed(feed); err != nil {
- util.Error(err)
+ log.Error(err)
}
}
diff --git a/internal/util/util.go b/internal/util/util.go
deleted file mode 100644
index 54a0805..0000000
--- a/internal/util/util.go
+++ /dev/null
@@ -1,17 +0,0 @@
-package util
-
-import (
- "log"
- "os"
-)
-
-var errorLogger = log.New(os.Stderr, "ERROR ", log.LstdFlags|log.Lmsgprefix)
-
-func Error(v ...interface{}) {
- errorLogger.Print(v...)
-}
-
-//noinspection GoUnusedExportedFunction
-func Errorf(format string, a ...interface{}) {
- errorLogger.Printf(format, a...)
-}
diff --git a/main.go b/main.go
index c155a1b..bbea985 100644
--- a/main.go
+++ b/main.go
@@ -2,19 +2,21 @@ package main
import (
"flag"
- "log"
"os"
"github.com/Necoro/feed2imap-go/internal/config"
+ "github.com/Necoro/feed2imap-go/internal/log"
"github.com/Necoro/feed2imap-go/internal/parse"
- "github.com/Necoro/feed2imap-go/internal/util"
)
var cfgFile = flag.String("f", "config.yml", "configuration file")
+var verbose = flag.Bool("v", false, "enable verbose output")
func run() error {
- log.Print("Starting up...")
flag.Parse()
+ log.SetDebug(*verbose)
+
+ log.Print("Starting up...")
log.Printf("Reading configuration file '%s'", *cfgFile)
cfg, err := config.Load(*cfgFile)
@@ -29,7 +31,7 @@ func run() error {
func main() {
if err := run(); err != nil {
- util.Error(err)
+ log.Error(err)
os.Exit(1)
}
}
s='insertions'>+100 2008-01-19 r675@Devoty: necoro | 2008-01-19 23:33:38 +0100Necoro2-366/+396 2008-01-18 r669@Devoty: necoro | 2008-01-18 22:49:33 +0100Necoro1-6/+6 2008-01-18 r664@Devoty: necoro | 2008-01-18 21:40:29 +0100Necoro5-26/+181 2008-01-18 r661@Devoty: necoro | 2008-01-18 14:16:59 +0100Necoro8-211/+293 2008-01-18 r655@Devoty: necoro | 2008-01-18 03:04:53 +0100Necoro1-1/+1 2008-01-18 r651@Devoty: necoro | 2008-01-18 02:41:51 +0100Necoro3-393/+513 2008-01-18 r643@Devoty: necoro | 2008-01-16 18:55:49 +0100Necoro14-249/+525 2008-01-14 r634@Devoty: necoro | 2008-01-14 23:48:24 +0100Necoro3-1/+4 2008-01-14 r632@Devoty: necoro | 2008-01-14 23:44:52 +0100Necoro3-175/+181 2008-01-14(no commit message)Necoro10-758/+1014 2008-01-14 r621@Devoty: necoro | 2008-01-14 20:21:40 +0100Necoro2-21/+61 2008-01-14 r618@Devoty: necoro | 2008-01-14 20:19:05 +0100Necoro2-35/+57 2008-01-14 r617@Devoty: necoro | 2008-01-14 19:12:59 +0100Necoro2-10/+10 2008-01-14 r609@Devoty: necoro | 2008-01-14 17:04:38 +0100Necoro9-394/+477 2008-01-14 r605@Devoty: necoro | 2008-01-14 11:43:34 +0100Necoro2-26/+129 2008-01-14 r603@Devoty: necoro | 2008-01-14 11:30:26 +0100Necoro4-26/+38 2008-01-11 r598@Devoty: necoro | 2008-01-10 16:36:29 +0100Necoro4-10/+50 2008-01-11 r597@Devoty: necoro | 2008-01-10 14:12:35 +0100Necoro1-3/+3 2008-01-10 r595@Devoty: necoro | 2008-01-10 04:04:15 +0100Necoro1-52/+3 2008-01-09 r586@Devoty: necoro | 2008-01-09 14:54:18 +0100Necoro1-1/+1 2007-12-06 r577@Devoty: necoro | 2007-12-06 20:37:36 +0100Necoro1-1/+1 2007-12-06 r572@Devoty: necoro | 2007-11-28 08:48:15 +0100Necoro1-0/+1 2007-11-27 r570@Devoty: necoro | 2007-11-27 02:08:21 +0100Necoro3-84/+108