File tree Expand file tree Collapse file tree 1 file changed +23
-1
lines changed
Expand file tree Collapse file tree 1 file changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -8,16 +8,19 @@ package main
88
99import (
1010 "fmt"
11+ "io"
1112 "os"
1213
1314 "github.com/Open-CMSIS-Pack/cbuild2cmake/cmd/cbuild2cmake/commands"
1415
1516 log "github.com/sirupsen/logrus"
17+ "github.com/sirupsen/logrus/hooks/writer"
1618)
1719
1820func main () {
1921 log .SetFormatter (new (LogFormatter ))
20- log .SetOutput (os .Stdout )
22+ log .SetOutput (io .Discard )
23+ initLogHooks ()
2124
2225 if len (version ) == 0 {
2326 version = "0.0.0-debug"
@@ -39,3 +42,22 @@ func (s *LogFormatter) Format(entry *log.Entry) ([]byte, error) {
3942 msg := fmt .Sprintf ("%s cbuild2cmake: %s\n " , entry .Level .String (), entry .Message )
4043 return []byte (msg ), nil
4144}
45+
46+ func initLogHooks () {
47+ log .AddHook (& writer.Hook { // Send logs with level higher than warning to stderr
48+ Writer : os .Stderr ,
49+ LogLevels : []log.Level {
50+ log .PanicLevel ,
51+ log .FatalLevel ,
52+ log .ErrorLevel ,
53+ log .WarnLevel ,
54+ },
55+ })
56+ log .AddHook (& writer.Hook { // Send info and debug logs to stdout
57+ Writer : os .Stdout ,
58+ LogLevels : []log.Level {
59+ log .InfoLevel ,
60+ log .DebugLevel ,
61+ },
62+ })
63+ }
You can’t perform that action at this time.
0 commit comments