mirror of https://github.com/nealey/spongy
Some logging
This commit is contained in:
parent
5189762e8f
commit
57a5de6dc1
|
@ -6,6 +6,7 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
"path/filepath"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -28,6 +29,7 @@ func runsvdir(dirname string) {
|
||||||
}
|
}
|
||||||
defer dir.Close()
|
defer dir.Close()
|
||||||
|
|
||||||
|
log.Printf("Starting in %s\n", dirname)
|
||||||
for running {
|
for running {
|
||||||
dn, err := dir.Readdirnames(0); if err != nil {
|
dn, err := dir.Readdirnames(0); if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
|
@ -44,6 +46,7 @@ func runsvdir(dirname string) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Printf("Found new network %s", fpath)
|
||||||
newnet := NewNetwork(fpath)
|
newnet := NewNetwork(fpath)
|
||||||
services[fpath] = newnet
|
services[fpath] = newnet
|
||||||
go newnet.Connect()
|
go newnet.Connect()
|
||||||
|
@ -54,6 +57,7 @@ func runsvdir(dirname string) {
|
||||||
// If anything vanished, disconnect it
|
// If anything vanished, disconnect it
|
||||||
for fpath, nw := range services {
|
for fpath, nw := range services {
|
||||||
if _, ok := found[fpath]; ! ok {
|
if _, ok := found[fpath]; ! ok {
|
||||||
|
log.Printf("Removing vanished network %s", fpath)
|
||||||
nw.Close()
|
nw.Close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -75,11 +79,21 @@ func usage() {
|
||||||
func main() {
|
func main() {
|
||||||
flag.Usage = usage
|
flag.Usage = usage
|
||||||
flag.UintVar(&maxlogsize, "logsize", 1000, "Log entries before rotating")
|
flag.UintVar(&maxlogsize, "logsize", 1000, "Log entries before rotating")
|
||||||
|
notime := flag.Bool("notime", false, "Don't timestamp log messages")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
if flag.NArg() != 1 {
|
if flag.NArg() != 1 {
|
||||||
usage()
|
usage()
|
||||||
os.Exit(2)
|
os.Exit(2)
|
||||||
}
|
}
|
||||||
runsvdir(flag.Arg(0))
|
basePath, err := filepath.Abs(flag.Arg(0))
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
if *notime {
|
||||||
|
log.SetFlags(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
runsvdir(basePath)
|
||||||
|
|
||||||
running = false
|
running = false
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue