-
-
Notifications
You must be signed in to change notification settings - Fork 240
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #73 from sam80180/main
fix: launch app with environment variables and arguments
- Loading branch information
Showing
13 changed files
with
110 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,60 @@ | ||
package util | ||
|
||
import ( | ||
stdlog "log" | ||
"os" | ||
"regexp" | ||
"strings" | ||
|
||
"github.com/sirupsen/logrus" | ||
easy "github.com/t-tomalak/logrus-easy-formatter" | ||
) | ||
|
||
func InitLogger() { | ||
func InitLogger(strIntLevel string) { | ||
logrus.SetOutput(os.Stderr) | ||
logrus.SetFormatter(&easy.Formatter{ | ||
TimestampFormat: "2006-01-02 15:04:05", | ||
LogFormat: "[%lvl%]: %time% - %msg%\n", | ||
}) | ||
SetLogLevel(strIntLevel) | ||
stdlog.SetOutput(new(LogrusWriter)) | ||
} | ||
|
||
func SetLogLevel(strIntLevel string) { | ||
loglevel := logrus.InfoLevel | ||
switch strings.ToLower(strIntLevel) { | ||
case "panic": | ||
loglevel = logrus.PanicLevel | ||
case "fatal": | ||
loglevel = logrus.FatalLevel | ||
case "error": | ||
loglevel = logrus.ErrorLevel | ||
case "warn": | ||
loglevel = logrus.WarnLevel | ||
case "info": | ||
loglevel = logrus.InfoLevel | ||
case "debug": | ||
loglevel = logrus.DebugLevel | ||
case "trace": | ||
loglevel = logrus.TraceLevel | ||
} | ||
logrus.SetLevel(loglevel) | ||
} | ||
|
||
/********** work around to this problem **********/ | ||
// https://github.com/google/gousb/issues/87#issuecomment-1100956460 | ||
type LogrusWriter int | ||
|
||
var reStdGoLogFormat = regexp.MustCompile(`(?s)[0-9]{4}/[0-9]{2}/[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2} (?P<msg>.+)`) | ||
|
||
func (LogrusWriter) Write(data []byte) (int, error) { | ||
logmessage := string(data) | ||
if reStdGoLogFormat.MatchString(logmessage) { | ||
logmessage = logmessage[20:] | ||
} | ||
if strings.HasSuffix(logmessage, "\n") { | ||
logmessage = logmessage[:len(logmessage)-1] | ||
} | ||
logrus.Infof("[gousb] %s", logmessage) | ||
return len(logmessage), nil | ||
} |