From 0838928668de232beb00c595149b28cc31ff5a52 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Sun, 27 Jan 2019 13:31:43 +0000 Subject: [PATCH] Add support for flexible logging levels --- cmd/yggdrasil/main.go | 25 ++++++++++++++++++++----- go.mod | 1 + go.sum | 2 ++ src/yggdrasil/admin.go | 12 ++++++------ src/yggdrasil/awdl.go | 12 ++++++------ src/yggdrasil/ckr.go | 10 +++++----- src/yggdrasil/core.go | 27 ++++++++++++++------------- src/yggdrasil/mobile.go | 2 -- src/yggdrasil/multicast.go | 6 +++--- src/yggdrasil/router.go | 2 +- src/yggdrasil/switch.go | 2 +- src/yggdrasil/tcp.go | 16 ++++++++-------- src/yggdrasil/tun.go | 6 +++--- src/yggdrasil/tun_bsd.go | 22 +++++++++++----------- src/yggdrasil/tun_darwin.go | 12 ++++++------ src/yggdrasil/tun_linux.go | 6 +++--- src/yggdrasil/tun_other.go | 2 +- src/yggdrasil/tun_windows.go | 28 ++++++++++++++-------------- 18 files changed, 105 insertions(+), 88 deletions(-) diff --git a/cmd/yggdrasil/main.go b/cmd/yggdrasil/main.go index f11bbc0d..f67bbcef 100644 --- a/cmd/yggdrasil/main.go +++ b/cmd/yggdrasil/main.go @@ -6,7 +6,6 @@ import ( "flag" "fmt" "io/ioutil" - "log" "os" "os/signal" "strings" @@ -14,6 +13,7 @@ import ( "golang.org/x/text/encoding/unicode" + "github.com/gologme/log" "github.com/hjson/hjson-go" "github.com/kardianos/minwinsvc" "github.com/mitchellh/mapstructure" @@ -169,6 +169,7 @@ func main() { confjson := flag.Bool("json", false, "print configuration from -genconf or -normaliseconf as JSON instead of HJSON") autoconf := flag.Bool("autoconf", false, "automatic mode (dynamic IP, peer with IPv6 neighbors)") 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") flag.Parse() var cfg *nodeConfig @@ -217,6 +218,20 @@ func main() { } // Create a new logger that logs output to stdout. logger := log.New(os.Stdout, "", log.Flags()) + //logger.EnableLevel("error") + //logger.EnableLevel("warn") + //logger.EnableLevel("info") + if levels := strings.Split(*logging, ","); len(levels) > 0 { + for _, level := range levels { + l := strings.TrimSpace(level) + switch l { + case "error", "warn", "info", "trace", "debug": + logger.EnableLevel(l) + default: + continue + } + } + } // Setup the Yggdrasil node itself. The node{} type includes a Core, so we // don't need to create this manually. n := node{} @@ -224,7 +239,7 @@ func main() { // Yggdrasil. This will start the router, switch, DHT node, TCP and UDP // sockets, TUN/TAP adapter and multicast discovery port. if err := n.core.Start(cfg, logger); err != nil { - logger.Println("An error occurred during startup") + logger.Errorln("An error occurred during startup") panic(err) } // The Stop function ensures that the TUN/TAP adapter is correctly shut down @@ -236,8 +251,8 @@ func main() { // This is just logged to stdout for the user. address := n.core.GetAddress() subnet := n.core.GetSubnet() - logger.Printf("Your IPv6 address is %s", address.String()) - logger.Printf("Your IPv6 subnet is %s", subnet.String()) + logger.Infof("Your IPv6 address is %s", address.String()) + logger.Infof("Your IPv6 subnet is %s", subnet.String()) // Catch interrupts from the operating system to exit gracefully. c := make(chan os.Signal, 1) r := make(chan os.Signal, 1) @@ -257,7 +272,7 @@ func main() { cfg = readConfig(useconf, useconffile, normaliseconf) n.core.UpdateConfig(cfg) } else { - logger.Println("Reloading config at runtime is only possible with -useconffile") + logger.Errorln("Reloading config at runtime is only possible with -useconffile") } case _ = <-c: goto exit diff --git a/go.mod b/go.mod index 53a5a2b9..3e8db512 100644 --- a/go.mod +++ b/go.mod @@ -5,6 +5,7 @@ require ( github.com/hjson/hjson-go v0.0.0-20181010104306-a25ecf6bd222 github.com/kardianos/minwinsvc v0.0.0-20151122163309-cad6b2b879b0 github.com/mitchellh/mapstructure v1.1.2 + github.com/gologme/log v0.0.0-20181207131047-4e5d8ccb38e8 github.com/songgao/packets v0.0.0-20160404182456-549a10cd4091 github.com/yggdrasil-network/water v0.0.0-20180615095340-f732c88f34ae golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9 diff --git a/go.sum b/go.sum index 1695daff..17b1017a 100644 --- a/go.sum +++ b/go.sum @@ -18,3 +18,5 @@ golang.org/x/sys v0.0.0-20181206074257-70b957f3b65e h1:njOxP/wVblhCLIUhjHXf6X+dz golang.org/x/sys v0.0.0-20181206074257-70b957f3b65e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +github.com/gologme/log v0.0.0-20181207131047-4e5d8ccb38e8 h1:WD8iJ37bRNwvETMfVTusVSAi0WdXTpfNVGY2aHycNKY= +github.com/gologme/log v0.0.0-20181207131047-4e5d8ccb38e8/go.mod h1:gq31gQ8wEHkR+WekdWsqDuf8pXTUZA9BnnzTuPz1Y9U= diff --git a/src/yggdrasil/admin.go b/src/yggdrasil/admin.go index f601776a..b54ac5cf 100644 --- a/src/yggdrasil/admin.go +++ b/src/yggdrasil/admin.go @@ -398,7 +398,7 @@ func (a *admin) listen() { switch strings.ToLower(u.Scheme) { case "unix": if _, err := os.Stat(a.listenaddr[7:]); err == nil { - a.core.log.Println("WARNING:", a.listenaddr[7:], "already exists and may be in use by another process") + a.core.log.Warnln("WARNING:", a.listenaddr[7:], "already exists and may be in use by another process") } a.listener, err = net.Listen("unix", a.listenaddr[7:]) if err == nil { @@ -406,7 +406,7 @@ func (a *admin) listen() { case "@": // maybe abstract namespace default: if err := os.Chmod(a.listenaddr[7:], 0660); err != nil { - a.core.log.Println("WARNING:", a.listenaddr[:7], "may have unsafe permissions!") + a.core.log.Warnln("WARNING:", a.listenaddr[:7], "may have unsafe permissions!") } } } @@ -420,10 +420,10 @@ func (a *admin) listen() { a.listener, err = net.Listen("tcp", a.listenaddr) } if err != nil { - a.core.log.Printf("Admin socket failed to listen: %v", err) + a.core.log.Errorf("Admin socket failed to listen: %v", err) os.Exit(1) } - a.core.log.Printf("%s admin socket listening on %s", + a.core.log.Infof("%s admin socket listening on %s", strings.ToUpper(a.listener.Addr().Network()), a.listener.Addr().String()) defer a.listener.Close() @@ -450,9 +450,9 @@ func (a *admin) handleRequest(conn net.Conn) { "status": "error", "error": "Unrecoverable error, possibly as a result of invalid input types or malformed syntax", } - fmt.Println("Admin socket error:", r) + a.core.log.Errorln("Admin socket error:", r) if err := encoder.Encode(&send); err != nil { - fmt.Println("Admin socket JSON encode error:", err) + a.core.log.Errorln("Admin socket JSON encode error:", err) } conn.Close() } diff --git a/src/yggdrasil/awdl.go b/src/yggdrasil/awdl.go index 633d5f9c..190d0258 100644 --- a/src/yggdrasil/awdl.go +++ b/src/yggdrasil/awdl.go @@ -50,24 +50,24 @@ func (l *awdl) create(fromAWDL chan []byte, toAWDL chan []byte /*boxPubKey *cryp meta.sig = l.core.sigPub meta.link = *myLinkPub metaBytes := meta.encode() - l.core.log.Println("toAWDL <- metaBytes") + l.core.log.Traceln("toAWDL <- metaBytes") toAWDL <- metaBytes - l.core.log.Println("metaBytes = <-fromAWDL") + l.core.log.Traceln("metaBytes = <-fromAWDL") metaBytes = <-fromAWDL - l.core.log.Println("version_metadata{}") + l.core.log.Traceln("version_metadata{}") meta = version_metadata{} if !meta.decode(metaBytes) || !meta.check() { return nil, errors.New("Metadata decode failure") } - l.core.log.Println("version_getBaseMetadata{}") + l.core.log.Traceln("version_getBaseMetadata{}") base := version_getBaseMetadata() if meta.ver > base.ver || meta.ver == base.ver && meta.minorVer > base.minorVer { return nil, errors.New("Failed to connect to node: " + name + " version: " + fmt.Sprintf("%d.%d", meta.ver, meta.minorVer)) } - l.core.log.Println("crypto.GetSharedKey") + l.core.log.Traceln("crypto.GetSharedKey") shared := crypto.GetSharedKey(myLinkPriv, &meta.link) //shared := crypto.GetSharedKey(&l.core.boxPriv, boxPubKey) - l.core.log.Println("l.core.peers.newPeer") + l.core.log.Traceln("l.core.peers.newPeer") intf.peer = l.core.peers.newPeer(&meta.box, &meta.sig, shared, name) if intf.peer != nil { intf.peer.linkOut = make(chan []byte, 1) // protocol traffic diff --git a/src/yggdrasil/ckr.go b/src/yggdrasil/ckr.go index a5ed4552..03bc5718 100644 --- a/src/yggdrasil/ckr.go +++ b/src/yggdrasil/ckr.go @@ -48,7 +48,7 @@ func (c *cryptokey) init(core *Core) { }() if err := c.configure(); err != nil { - c.core.log.Println("CKR configuration failed:", err) + c.core.log.Errorln("CKR configuration failed:", err) } } @@ -192,7 +192,7 @@ func (c *cryptokey) addSourceSubnet(cidr string) error { // Add the source subnet *routingsources = append(*routingsources, *ipnet) - c.core.log.Println("Added CKR source subnet", cidr) + c.core.log.Infoln("Added CKR source subnet", cidr) return nil } @@ -264,7 +264,7 @@ func (c *cryptokey) addRoute(cidr string, dest string) error { delete(*routingcache, k) } - c.core.log.Println("Added CKR destination subnet", cidr) + c.core.log.Infoln("Added CKR destination subnet", cidr) return nil } } @@ -358,7 +358,7 @@ func (c *cryptokey) removeSourceSubnet(cidr string) error { for idx, subnet := range *routingsources { if subnet.String() == ipnet.String() { *routingsources = append((*routingsources)[:idx], (*routingsources)[idx+1:]...) - c.core.log.Println("Removed CKR source subnet", cidr) + c.core.log.Infoln("Removed CKR source subnet", cidr) return nil } } @@ -407,7 +407,7 @@ func (c *cryptokey) removeRoute(cidr string, dest string) error { for k := range *routingcache { delete(*routingcache, k) } - c.core.log.Printf("Removed CKR destination subnet %s via %s\n", cidr, dest) + c.core.log.Infoln("Removed CKR destination subnet %s via %s\n", cidr, dest) return nil } } diff --git a/src/yggdrasil/core.go b/src/yggdrasil/core.go index ed075813..c78bc1fb 100644 --- a/src/yggdrasil/core.go +++ b/src/yggdrasil/core.go @@ -3,11 +3,12 @@ package yggdrasil import ( "encoding/hex" "io/ioutil" - "log" "net" "sync" "time" + "github.com/gologme/log" + "github.com/yggdrasil-network/yggdrasil-go/src/address" "github.com/yggdrasil-network/yggdrasil-go/src/config" "github.com/yggdrasil-network/yggdrasil-go/src/crypto" @@ -178,13 +179,13 @@ func (c *Core) Start(nc *config.NodeConfig, log *log.Logger) error { c.log = log if name := GetBuildName(); name != "unknown" { - c.log.Println("Build name:", name) + c.log.Infoln("Build name:", name) } if version := GetBuildVersion(); version != "unknown" { - c.log.Println("Build version:", version) + c.log.Infoln("Build version:", version) } - c.log.Println("Starting up...") + c.log.Infoln("Starting up...") c.configMutex.Lock() c.config = *nc @@ -194,12 +195,12 @@ func (c *Core) Start(nc *config.NodeConfig, log *log.Logger) error { c.init() if err := c.tcp.init(c); err != nil { - c.log.Println("Failed to start TCP interface") + c.log.Errorln("Failed to start TCP interface") return err } if err := c.awdl.init(c); err != nil { - c.log.Println("Failed to start AWDL interface") + c.log.Errorln("Failed to start AWDL interface") return err } @@ -208,39 +209,39 @@ func (c *Core) Start(nc *config.NodeConfig, log *log.Logger) error { } if err := c.switchTable.start(); err != nil { - c.log.Println("Failed to start switch") + c.log.Errorln("Failed to start switch") return err } if err := c.router.start(); err != nil { - c.log.Println("Failed to start router") + c.log.Errorln("Failed to start router") return err } if err := c.admin.start(); err != nil { - c.log.Println("Failed to start admin socket") + c.log.Errorln("Failed to start admin socket") return err } if err := c.multicast.start(); err != nil { - c.log.Println("Failed to start multicast interface") + c.log.Errorln("Failed to start multicast interface") return err } if err := c.router.tun.start(); err != nil { - c.log.Println("Failed to start TUN/TAP") + c.log.Errorln("Failed to start TUN/TAP") return err } go c.addPeerLoop() - c.log.Println("Startup complete") + c.log.Infoln("Startup complete") return nil } // Stops the Yggdrasil node. func (c *Core) Stop() { - c.log.Println("Stopping...") + c.log.Infoln("Stopping...") c.router.tun.close() c.admin.close() } diff --git a/src/yggdrasil/mobile.go b/src/yggdrasil/mobile.go index 2ffeffb9..220e6ca7 100644 --- a/src/yggdrasil/mobile.go +++ b/src/yggdrasil/mobile.go @@ -77,9 +77,7 @@ func (c *Core) StartJSON(configjson []byte) error { return err } nc.IfName = "dummy" - //c.log.Println(nc.MulticastInterfaces) for _, ll := range nc.MulticastInterfaces { - //c.log.Println("Processing MC", ll) ifceExpr, err := regexp.Compile(ll) if err != nil { panic(err) diff --git a/src/yggdrasil/multicast.go b/src/yggdrasil/multicast.go index 08f0954e..42651deb 100644 --- a/src/yggdrasil/multicast.go +++ b/src/yggdrasil/multicast.go @@ -35,15 +35,15 @@ func (m *multicast) init(core *Core) { m.groupAddr = "[ff02::114]:9001" // Check if we've been given any expressions if count := len(m.interfaces()); count != 0 { - m.core.log.Println("Found", count, "multicast interface(s)") + m.core.log.Infoln("Found", count, "multicast interface(s)") } } func (m *multicast) start() error { if len(m.interfaces()) == 0 { - m.core.log.Println("Multicast discovery is disabled") + m.core.log.Infoln("Multicast discovery is disabled") } else { - m.core.log.Println("Multicast discovery is enabled") + m.core.log.Infoln("Multicast discovery is enabled") addr, err := net.ResolveUDPAddr("udp", m.groupAddr) if err != nil { return err diff --git a/src/yggdrasil/router.go b/src/yggdrasil/router.go index 31eefbb2..d5059369 100644 --- a/src/yggdrasil/router.go +++ b/src/yggdrasil/router.go @@ -96,7 +96,7 @@ func (r *router) init(core *Core) { // Starts the mainLoop goroutine. func (r *router) start() error { - r.core.log.Println("Starting router") + r.core.log.Infoln("Starting router") go r.mainLoop() return nil } diff --git a/src/yggdrasil/switch.go b/src/yggdrasil/switch.go index 2a4e7e46..f2adf3fb 100644 --- a/src/yggdrasil/switch.go +++ b/src/yggdrasil/switch.go @@ -563,7 +563,7 @@ func (t *switchTable) getTable() lookupTable { // Starts the switch worker func (t *switchTable) start() error { - t.core.log.Println("Starting switch") + t.core.log.Infoln("Starting switch") go t.doWorker() return nil } diff --git a/src/yggdrasil/tcp.go b/src/yggdrasil/tcp.go index 78e39efc..a83213d4 100644 --- a/src/yggdrasil/tcp.go +++ b/src/yggdrasil/tcp.go @@ -139,16 +139,16 @@ func (iface *tcpInterface) listen() error { // Runs the listener, which spawns off goroutines for incoming connections. func (iface *tcpInterface) listener() { defer iface.serv.Close() - iface.core.log.Println("Listening for TCP on:", iface.serv.Addr().String()) + iface.core.log.Infoln("Listening for TCP on:", iface.serv.Addr().String()) for { sock, err := iface.serv.Accept() if err != nil { - iface.core.log.Println("Failed to accept connection:", err) + iface.core.log.Errorln("Failed to accept connection:", err) return } select { case <-iface.serv_stop: - iface.core.log.Println("Stopping listener") + iface.core.log.Errorln("Stopping listener") return default: if err != nil { @@ -313,9 +313,9 @@ func (iface *tcpInterface) handler(sock net.Conn, incoming bool) { base := version_getBaseMetadata() if meta.meta == base.meta { if meta.ver > base.ver { - iface.core.log.Println("Failed to connect to node:", sock.RemoteAddr().String(), "version:", meta.ver) + iface.core.log.Errorln("Failed to connect to node:", sock.RemoteAddr().String(), "version:", meta.ver) } else if meta.ver == base.ver && meta.minorVer > base.minorVer { - iface.core.log.Println("Failed to connect to node:", sock.RemoteAddr().String(), "version:", fmt.Sprintf("%d.%d", meta.ver, meta.minorVer)) + iface.core.log.Errorln("Failed to connect to node:", sock.RemoteAddr().String(), "version:", fmt.Sprintf("%d.%d", meta.ver, meta.minorVer)) } } // TODO? Block forever to prevent future connection attempts? suppress future messages about the same node? @@ -444,12 +444,12 @@ func (iface *tcpInterface) handler(sock net.Conn, incoming bool) { themAddr := address.AddrForNodeID(themNodeID) themAddrString := net.IP(themAddr[:]).String() themString := fmt.Sprintf("%s@%s", themAddrString, them) - iface.core.log.Printf("Connected: %s, source: %s", themString, us) + iface.core.log.Infof("Connected: %s, source: %s", themString, us) err = iface.reader(sock, in) // In this goroutine, because of defers if err == nil { - iface.core.log.Printf("Disconnected: %s, source: %s", themString, us) + iface.core.log.Infof("Disconnected: %s, source: %s", themString, us) } else { - iface.core.log.Printf("Disconnected: %s, source: %s, error: %s", themString, us, err) + iface.core.log.Infof("Disconnected: %s, source: %s, error: %s", themString, us, err) } return } diff --git a/src/yggdrasil/tun.go b/src/yggdrasil/tun.go index c0a71396..465cbb1c 100644 --- a/src/yggdrasil/tun.go +++ b/src/yggdrasil/tun.go @@ -53,7 +53,7 @@ func (tun *tunAdapter) init(core *Core, send chan<- []byte, recv <-chan []byte) tun.core.config.IfMTU != tun.core.configOld.IfMTU tun.core.configMutex.RUnlock() if updated { - tun.core.log.Println("Reconfiguring TUN/TAP is not supported yet") + tun.core.log.Warnln("Reconfiguring TUN/TAP is not supported yet") e <- nil } else { e <- nil @@ -82,8 +82,8 @@ func (tun *tunAdapter) start() error { tun.mutex.Lock() tun.isOpen = true tun.mutex.Unlock() - go func() { tun.core.log.Println("WARNING: tun.read() exited with error:", tun.read()) }() - go func() { tun.core.log.Println("WARNING: tun.write() exited with error:", tun.write()) }() + go func() { tun.core.log.Errorln("WARNING: tun.read() exited with error:", tun.read()) }() + go func() { tun.core.log.Errorln("WARNING: tun.write() exited with error:", tun.write()) }() if iftapmode { go func() { for { diff --git a/src/yggdrasil/tun_bsd.go b/src/yggdrasil/tun_bsd.go index 620c79db..81e2c46c 100644 --- a/src/yggdrasil/tun_bsd.go +++ b/src/yggdrasil/tun_bsd.go @@ -114,9 +114,9 @@ func (tun *tunAdapter) setupAddress(addr string) error { } // Friendly output - tun.core.log.Printf("Interface name: %s", tun.iface.Name()) - tun.core.log.Printf("Interface IPv6: %s", addr) - tun.core.log.Printf("Interface MTU: %d", tun.mtu) + tun.core.log.Infof("Interface name: %s", tun.iface.Name()) + tun.core.log.Infof("Interface IPv6: %s", addr) + tun.core.log.Infof("Interface MTU: %d", tun.mtu) // Create the MTU request var ir in6_ifreq_mtu @@ -126,15 +126,15 @@ func (tun *tunAdapter) setupAddress(addr string) error { // Set the MTU if _, _, errno := unix.Syscall(unix.SYS_IOCTL, uintptr(sfd), uintptr(syscall.SIOCSIFMTU), uintptr(unsafe.Pointer(&ir))); errno != 0 { err = errno - tun.core.log.Printf("Error in SIOCSIFMTU: %v", errno) + tun.core.log.Errorf("Error in SIOCSIFMTU: %v", errno) // Fall back to ifconfig to set the MTU cmd := exec.Command("ifconfig", tun.iface.Name(), "mtu", string(tun.mtu)) - tun.core.log.Printf("Using ifconfig as fallback: %v", strings.Join(cmd.Args, " ")) + tun.core.log.Warnf("Using ifconfig as fallback: %v", strings.Join(cmd.Args, " ")) output, err := cmd.CombinedOutput() if err != nil { - tun.core.log.Printf("SIOCSIFMTU fallback failed: %v.", err) - tun.core.log.Println(string(output)) + tun.core.log.Errorf("SIOCSIFMTU fallback failed: %v.", err) + tun.core.log.Traceln(string(output)) } } @@ -155,15 +155,15 @@ func (tun *tunAdapter) setupAddress(addr string) error { // Set the interface address if _, _, errno := unix.Syscall(unix.SYS_IOCTL, uintptr(sfd), uintptr(SIOCSIFADDR_IN6), uintptr(unsafe.Pointer(&ar))); errno != 0 { err = errno - tun.core.log.Printf("Error in SIOCSIFADDR_IN6: %v", errno) + tun.core.log.Errorf("Error in SIOCSIFADDR_IN6: %v", errno) // Fall back to ifconfig to set the address cmd := exec.Command("ifconfig", tun.iface.Name(), "inet6", addr) - tun.core.log.Printf("Using ifconfig as fallback: %v", strings.Join(cmd.Args, " ")) + tun.core.log.Warnf("Using ifconfig as fallback: %v", strings.Join(cmd.Args, " ")) output, err := cmd.CombinedOutput() if err != nil { - tun.core.log.Printf("SIOCSIFADDR_IN6 fallback failed: %v.", err) - tun.core.log.Println(string(output)) + tun.core.log.Errorf("SIOCSIFADDR_IN6 fallback failed: %v.", err) + tun.core.log.Traceln(string(output)) } } diff --git a/src/yggdrasil/tun_darwin.go b/src/yggdrasil/tun_darwin.go index 828c01ea..7ec1b8b9 100644 --- a/src/yggdrasil/tun_darwin.go +++ b/src/yggdrasil/tun_darwin.go @@ -18,7 +18,7 @@ import ( // Configures the "utun" adapter with the correct IPv6 address and MTU. func (tun *tunAdapter) setup(ifname string, iftapmode bool, addr string, mtu int) error { if iftapmode { - tun.core.log.Printf("TAP mode is not supported on this platform, defaulting to TUN") + tun.core.log.Warnln("TAP mode is not supported on this platform, defaulting to TUN") } config := water.Config{DeviceType: water.TUN} iface, err := water.New(config) @@ -98,19 +98,19 @@ func (tun *tunAdapter) setupAddress(addr string) error { copy(ir.ifr_name[:], tun.iface.Name()) ir.ifru_mtu = uint32(tun.mtu) - tun.core.log.Printf("Interface name: %s", ar.ifra_name) - tun.core.log.Printf("Interface IPv6: %s", addr) - tun.core.log.Printf("Interface MTU: %d", ir.ifru_mtu) + tun.core.log.Infof("Interface name: %s", ar.ifra_name) + tun.core.log.Infof("Interface IPv6: %s", addr) + tun.core.log.Infof("Interface MTU: %d", ir.ifru_mtu) if _, _, errno := unix.Syscall(unix.SYS_IOCTL, uintptr(fd), uintptr(darwin_SIOCAIFADDR_IN6), uintptr(unsafe.Pointer(&ar))); errno != 0 { err = errno - tun.core.log.Printf("Error in darwin_SIOCAIFADDR_IN6: %v", errno) + tun.core.log.Errorf("Error in darwin_SIOCAIFADDR_IN6: %v", errno) return err } if _, _, errno := unix.Syscall(unix.SYS_IOCTL, uintptr(fd), uintptr(unix.SIOCSIFMTU), uintptr(unsafe.Pointer(&ir))); errno != 0 { err = errno - tun.core.log.Printf("Error in SIOCSIFMTU: %v", errno) + tun.core.log.Errorf("Error in SIOCSIFMTU: %v", errno) return err } diff --git a/src/yggdrasil/tun_linux.go b/src/yggdrasil/tun_linux.go index 8ccdd30b..30ada235 100644 --- a/src/yggdrasil/tun_linux.go +++ b/src/yggdrasil/tun_linux.go @@ -40,9 +40,9 @@ func (tun *tunAdapter) setup(ifname string, iftapmode bool, addr string, mtu int } } // Friendly output - tun.core.log.Printf("Interface name: %s", tun.iface.Name()) - tun.core.log.Printf("Interface IPv6: %s", addr) - tun.core.log.Printf("Interface MTU: %d", tun.mtu) + tun.core.log.Infof("Interface name: %s", tun.iface.Name()) + tun.core.log.Infof("Interface IPv6: %s", addr) + tun.core.log.Infof("Interface MTU: %d", tun.mtu) return tun.setupAddress(addr) } diff --git a/src/yggdrasil/tun_other.go b/src/yggdrasil/tun_other.go index 22058c11..07ec25fd 100644 --- a/src/yggdrasil/tun_other.go +++ b/src/yggdrasil/tun_other.go @@ -28,6 +28,6 @@ func (tun *tunAdapter) setup(ifname string, iftapmode bool, addr string, mtu int // We don't know how to set the IPv6 address on an unknown platform, therefore // write about it to stdout and don't try to do anything further. func (tun *tunAdapter) setupAddress(addr string) error { - tun.core.log.Println("Platform not supported, you must set the address of", tun.iface.Name(), "to", addr) + tun.core.log.Warnln("Platform not supported, you must set the address of", tun.iface.Name(), "to", addr) return nil } diff --git a/src/yggdrasil/tun_windows.go b/src/yggdrasil/tun_windows.go index 150a9766..1c89a437 100644 --- a/src/yggdrasil/tun_windows.go +++ b/src/yggdrasil/tun_windows.go @@ -15,7 +15,7 @@ import ( // delegate the hard work to "netsh". func (tun *tunAdapter) setup(ifname string, iftapmode bool, addr string, mtu int) error { if !iftapmode { - tun.core.log.Printf("TUN mode is not supported on this platform, defaulting to TAP") + tun.core.log.Warnln("TUN mode is not supported on this platform, defaulting to TAP") } config := water.Config{DeviceType: water.TAP} config.PlatformSpecificParams.ComponentID = "tap0901" @@ -34,16 +34,16 @@ func (tun *tunAdapter) setup(ifname string, iftapmode bool, addr string, mtu int tun.core.log.Printf("netsh command: %v", strings.Join(cmd.Args, " ")) output, err := cmd.CombinedOutput() if err != nil { - tun.core.log.Printf("Windows netsh failed: %v.", err) - tun.core.log.Println(string(output)) + tun.core.log.Errorf("Windows netsh failed: %v.", err) + tun.core.log.Traceln(string(output)) return err } cmd = exec.Command("netsh", "interface", "set", "interface", iface.Name(), "admin=ENABLED") tun.core.log.Printf("netsh command: %v", strings.Join(cmd.Args, " ")) output, err = cmd.CombinedOutput() if err != nil { - tun.core.log.Printf("Windows netsh failed: %v.", err) - tun.core.log.Println(string(output)) + tun.core.log.Errorf("Windows netsh failed: %v.", err) + tun.core.log.Traceln(string(output)) return err } // Get a new iface @@ -58,9 +58,9 @@ func (tun *tunAdapter) setup(ifname string, iftapmode bool, addr string, mtu int panic(err) } // Friendly output - tun.core.log.Printf("Interface name: %s", tun.iface.Name()) - tun.core.log.Printf("Interface IPv6: %s", addr) - tun.core.log.Printf("Interface MTU: %d", tun.mtu) + tun.core.log.Infof("Interface name: %s", tun.iface.Name()) + tun.core.log.Infof("Interface IPv6: %s", addr) + tun.core.log.Infof("Interface MTU: %d", tun.mtu) return tun.setupAddress(addr) } @@ -71,11 +71,11 @@ func (tun *tunAdapter) setupMTU(mtu int) error { fmt.Sprintf("interface=%s", tun.iface.Name()), fmt.Sprintf("mtu=%d", mtu), "store=active") - tun.core.log.Printf("netsh command: %v", strings.Join(cmd.Args, " ")) + tun.core.log.Debugln("netsh command: %v", strings.Join(cmd.Args, " ")) output, err := cmd.CombinedOutput() if err != nil { - tun.core.log.Printf("Windows netsh failed: %v.", err) - tun.core.log.Println(string(output)) + tun.core.log.Errorf("Windows netsh failed: %v.", err) + tun.core.log.Traceln(string(output)) return err } return nil @@ -88,11 +88,11 @@ func (tun *tunAdapter) setupAddress(addr string) error { fmt.Sprintf("interface=%s", tun.iface.Name()), fmt.Sprintf("addr=%s", addr), "store=active") - tun.core.log.Printf("netsh command: %v", strings.Join(cmd.Args, " ")) + tun.core.log.Debugln("netsh command: %v", strings.Join(cmd.Args, " ")) output, err := cmd.CombinedOutput() if err != nil { - tun.core.log.Printf("Windows netsh failed: %v.", err) - tun.core.log.Println(string(output)) + tun.core.log.Errorf("Windows netsh failed: %v.", err) + tun.core.log.Traceln(string(output)) return err } return nil