diff --git a/log.go b/log.go index 6295ea9..227f510 100644 --- a/log.go +++ b/log.go @@ -47,7 +47,7 @@ const ( type V8log struct { loggers map[LogLevel]*log.Logger files map[LogLevel]*os.File - llevel LogLevel + level LogLevel stopSig chan bool logDir string mtx *sync.Mutex @@ -92,17 +92,10 @@ func InitLogger(path string, filePrefix string, level LogLevel, maxLogSize int64 return pLog } -// UninitLogger ... -func (vl *V8log) UninitLogger() { - if !vl.stoped { - vl.stoped = true - close(vl.stopSig) - for l := range logFileNames { - if l >= vl.llevel { - vl.files[l].Close() - } - } - } +func (vl *V8log) setLevel(level LogLevel) { + vl.mtx.Lock() + defer vl.mtx.Unlock() + vl.level = level } func (vl *V8log) checkFile() { @@ -150,7 +143,7 @@ func (vl *V8log) Printf(level LogLevel, format string, params ...interface{}) { if vl.stoped { return } - if level < vl.llevel { + if level < vl.level { return } pidAndLevel := []interface{}{vl.pid, loglevel[level]} @@ -170,7 +163,7 @@ func (vl *V8log) Println(level LogLevel, params ...interface{}) { if vl.stoped { return } - if level < vl.llevel { + if level < vl.level { return } pidAndLevel := []interface{}{vl.pid, " ", loglevel[level], " "} diff --git a/openp2p.go b/openp2p.go index 5af5908..e168e36 100644 --- a/openp2p.go +++ b/openp2p.go @@ -13,6 +13,7 @@ func main() { rand.Seed(time.Now().UnixNano()) binDir := filepath.Dir(os.Args[0]) os.Chdir(binDir) // for system service + gLog = InitLogger(binDir, "openp2p", LevelDEBUG, 1024*1024, LogFileAndConsole) // TODO: install sub command, deamon process // groups := flag.String("groups", "", "you could join in several groups. like: GroupName1:Password1;GroupName2:Password2; group name 8-31 characters") if len(os.Args) > 1 { @@ -74,7 +75,7 @@ func main() { gConf.add(config) gConf.load() gConf.mtx.Lock() - + gLog.setLevel(LogLevel(gConf.logLevel)) flag.Visit(func(f *flag.Flag) { if f.Name == "sharebandwidth" { gConf.Network.ShareBandwidth = *shareBandwidth @@ -95,7 +96,21 @@ func main() { gConf.logLevel = *logLevel } }) - gLog = InitLogger(binDir, "openp2p", LogLevel(gConf.logLevel), 1024*1024, LogFileAndConsole) + if gConf.Network.ServerHost == "" { + gConf.Network.ServerHost = *serverHost + } + if gConf.Network.Node == "" { + gConf.Network.Node = *node + } + if gConf.Network.User == "" { + gConf.Network.User = *user + } + if gConf.Network.Password == "" { + gConf.Network.Password = *password + } + gConf.Network.ServerPort = 27182 + gConf.Network.UDPPort1 = 27182 + gConf.Network.UDPPort2 = 27183 gLog.Println(LevelINFO, "openp2p start. version: ", OpenP2PVersion) gConf.mtx.Unlock() gConf.save() diff --git a/protocol.go b/protocol.go index 6255fab..b0e46ae 100644 --- a/protocol.go +++ b/protocol.go @@ -10,7 +10,7 @@ import ( "time" ) -const OpenP2PVersion = "0.98.0" +const OpenP2PVersion = "0.98.1" const ProducnName string = "openp2p" type openP2PHeader struct {