-
Notifications
You must be signed in to change notification settings - Fork 17
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 #83 from alexadhy/feature/windows-cmdutil
[WIP] windows cmdutil
- Loading branch information
Showing
6 changed files
with
105 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// +build !windows | ||
|
||
package cmdutil | ||
|
||
import ( | ||
"os" | ||
|
||
"golang.org/x/sys/unix" | ||
) | ||
|
||
func listenSignals() []os.Signal { | ||
return []os.Signal{unix.SIGINT, unix.SIGTERM, unix.SIGQUIT} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// +build windows | ||
|
||
package cmdutil | ||
|
||
import ( | ||
"os" | ||
|
||
"golang.org/x/sys/windows" | ||
) | ||
|
||
func listenSignals() []os.Signal { | ||
return []os.Signal{windows.SIGINT, windows.SIGTERM, windows.SIGQUIT} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// +build !windows | ||
|
||
package cmdutil | ||
|
||
import ( | ||
"log/syslog" | ||
"strings" | ||
|
||
"github.com/sirupsen/logrus" | ||
logrussyslog "github.com/sirupsen/logrus/hooks/syslog" | ||
"github.com/skycoin/skycoin/src/util/logging" | ||
) | ||
|
||
func (sf *ServiceFlags) sysLogHook(log *logging.Logger, sysLvl int) { | ||
hook, err := logrussyslog.NewSyslogHook(sf.SyslogNet, sf.Syslog, syslog.Priority(sysLvl), sf.Tag) | ||
if err != nil { | ||
log.WithError(err). | ||
WithField("net", sf.SyslogNet). | ||
WithField("addr", sf.Syslog). | ||
Fatal("Failed to connect to syslog daemon.") | ||
} | ||
logging.AddHook(hook) | ||
} | ||
|
||
// LevelFromString returns a logrus.Level and syslog.Priority from a string identifier. | ||
func LevelFromString(s string) (logrus.Level, int, error) { | ||
switch strings.ToLower(s) { | ||
case "debug": | ||
return logrus.DebugLevel, int(syslog.LOG_DEBUG), nil | ||
case "info", "notice": | ||
return logrus.InfoLevel, int(syslog.LOG_INFO), nil | ||
case "warn", "warning": | ||
return logrus.WarnLevel, int(syslog.LOG_WARNING), nil | ||
case "error": | ||
return logrus.ErrorLevel, int(syslog.LOG_ERR), nil | ||
case "fatal", "critical": | ||
return logrus.FatalLevel, int(syslog.LOG_CRIT), nil | ||
case "panic": | ||
return logrus.PanicLevel, int(syslog.LOG_EMERG), nil | ||
default: | ||
return logrus.DebugLevel, int(syslog.LOG_DEBUG), ErrInvalidLogString | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// +build windows | ||
|
||
package cmdutil | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/sirupsen/logrus" | ||
"github.com/skycoin/skycoin/src/util/logging" | ||
) | ||
|
||
func (sf *ServiceFlags) sysLogHook(_ *logging.Logger, _ int) { | ||
} | ||
|
||
// LevelFromString returns a logrus.Level and syslog.Priority from a string identifier. | ||
func LevelFromString(s string) (logrus.Level, int, error) { | ||
switch strings.ToLower(s) { | ||
case "debug": | ||
return logrus.DebugLevel, 0, nil | ||
case "info", "notice": | ||
return logrus.InfoLevel, 0, nil | ||
case "warn", "warning": | ||
return logrus.WarnLevel, 0, nil | ||
case "error": | ||
return logrus.ErrorLevel, 0, nil | ||
case "fatal", "critical": | ||
return logrus.FatalLevel, 0, nil | ||
case "panic": | ||
return logrus.PanicLevel, 0, nil | ||
default: | ||
return logrus.DebugLevel, 0, ErrInvalidLogString | ||
} | ||
} |