mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2024-11-27 00:41:35 +00:00
Merge pull request #440 from neilalexander/logging
Add support for logging to file or syslog instead of stdout
This commit is contained in:
commit
721a8b5d27
@ -15,6 +15,7 @@ import (
|
|||||||
"golang.org/x/text/encoding/unicode"
|
"golang.org/x/text/encoding/unicode"
|
||||||
|
|
||||||
"github.com/gologme/log"
|
"github.com/gologme/log"
|
||||||
|
gsyslog "github.com/hashicorp/go-syslog"
|
||||||
"github.com/hjson/hjson-go"
|
"github.com/hjson/hjson-go"
|
||||||
"github.com/kardianos/minwinsvc"
|
"github.com/kardianos/minwinsvc"
|
||||||
"github.com/mitchellh/mapstructure"
|
"github.com/mitchellh/mapstructure"
|
||||||
@ -114,6 +115,7 @@ func main() {
|
|||||||
autoconf := flag.Bool("autoconf", false, "automatic mode (dynamic IP, peer with IPv6 neighbors)")
|
autoconf := flag.Bool("autoconf", false, "automatic mode (dynamic IP, peer with IPv6 neighbors)")
|
||||||
version := flag.Bool("version", false, "prints the version of this build")
|
version := flag.Bool("version", false, "prints the version of this build")
|
||||||
logging := flag.String("logging", "info,warn,error", "comma-separated list of logging levels to enable")
|
logging := flag.String("logging", "info,warn,error", "comma-separated list of logging levels to enable")
|
||||||
|
logto := flag.String("logto", "stdout", "file path to log to, \"syslog\" or \"stdout\"")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
var cfg *config.NodeConfig
|
var cfg *config.NodeConfig
|
||||||
@ -161,7 +163,23 @@ func main() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
// Create a new logger that logs output to stdout.
|
// Create a new logger that logs output to stdout.
|
||||||
logger := log.New(os.Stdout, "", log.Flags())
|
var logger *log.Logger
|
||||||
|
switch *logto {
|
||||||
|
case "stdout":
|
||||||
|
logger = log.New(os.Stdout, "", log.Flags())
|
||||||
|
case "syslog":
|
||||||
|
if syslogger, err := gsyslog.NewLogger(gsyslog.LOG_NOTICE, "DAEMON", yggdrasil.BuildName()); err == nil {
|
||||||
|
logger = log.New(syslogger, "", log.Flags())
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
if logfd, err := os.Create(*logto); err == nil {
|
||||||
|
logger = log.New(logfd, "", log.Flags())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if logger == nil {
|
||||||
|
logger = log.New(os.Stdout, "", log.Flags())
|
||||||
|
logger.Warnln("Logging defaulting to stdout")
|
||||||
|
}
|
||||||
//logger.EnableLevel("error")
|
//logger.EnableLevel("error")
|
||||||
//logger.EnableLevel("warn")
|
//logger.EnableLevel("warn")
|
||||||
//logger.EnableLevel("info")
|
//logger.EnableLevel("info")
|
||||||
|
@ -232,7 +232,7 @@ func (c *Core) GetSessions() []Session {
|
|||||||
// from git, or returns "unknown" otherwise.
|
// from git, or returns "unknown" otherwise.
|
||||||
func BuildName() string {
|
func BuildName() string {
|
||||||
if buildName == "" {
|
if buildName == "" {
|
||||||
return "unknown"
|
return "yggdrasil"
|
||||||
}
|
}
|
||||||
return buildName
|
return buildName
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user