Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ac454ec694 |
@@ -47,7 +47,7 @@ const (
|
|||||||
type V8log struct {
|
type V8log struct {
|
||||||
loggers map[LogLevel]*log.Logger
|
loggers map[LogLevel]*log.Logger
|
||||||
files map[LogLevel]*os.File
|
files map[LogLevel]*os.File
|
||||||
llevel LogLevel
|
level LogLevel
|
||||||
stopSig chan bool
|
stopSig chan bool
|
||||||
logDir string
|
logDir string
|
||||||
mtx *sync.Mutex
|
mtx *sync.Mutex
|
||||||
@@ -92,17 +92,10 @@ func InitLogger(path string, filePrefix string, level LogLevel, maxLogSize int64
|
|||||||
return pLog
|
return pLog
|
||||||
}
|
}
|
||||||
|
|
||||||
// UninitLogger ...
|
func (vl *V8log) setLevel(level LogLevel) {
|
||||||
func (vl *V8log) UninitLogger() {
|
vl.mtx.Lock()
|
||||||
if !vl.stoped {
|
defer vl.mtx.Unlock()
|
||||||
vl.stoped = true
|
vl.level = level
|
||||||
close(vl.stopSig)
|
|
||||||
for l := range logFileNames {
|
|
||||||
if l >= vl.llevel {
|
|
||||||
vl.files[l].Close()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (vl *V8log) checkFile() {
|
func (vl *V8log) checkFile() {
|
||||||
@@ -150,7 +143,7 @@ func (vl *V8log) Printf(level LogLevel, format string, params ...interface{}) {
|
|||||||
if vl.stoped {
|
if vl.stoped {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if level < vl.llevel {
|
if level < vl.level {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
pidAndLevel := []interface{}{vl.pid, loglevel[level]}
|
pidAndLevel := []interface{}{vl.pid, loglevel[level]}
|
||||||
@@ -170,7 +163,7 @@ func (vl *V8log) Println(level LogLevel, params ...interface{}) {
|
|||||||
if vl.stoped {
|
if vl.stoped {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if level < vl.llevel {
|
if level < vl.level {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
pidAndLevel := []interface{}{vl.pid, " ", loglevel[level], " "}
|
pidAndLevel := []interface{}{vl.pid, " ", loglevel[level], " "}
|
||||||
|
|||||||
+17
-2
@@ -13,6 +13,7 @@ func main() {
|
|||||||
rand.Seed(time.Now().UnixNano())
|
rand.Seed(time.Now().UnixNano())
|
||||||
binDir := filepath.Dir(os.Args[0])
|
binDir := filepath.Dir(os.Args[0])
|
||||||
os.Chdir(binDir) // for system service
|
os.Chdir(binDir) // for system service
|
||||||
|
gLog = InitLogger(binDir, "openp2p", LevelDEBUG, 1024*1024, LogFileAndConsole)
|
||||||
// TODO: install sub command, deamon process
|
// 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")
|
// 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 {
|
if len(os.Args) > 1 {
|
||||||
@@ -74,7 +75,7 @@ func main() {
|
|||||||
gConf.add(config)
|
gConf.add(config)
|
||||||
gConf.load()
|
gConf.load()
|
||||||
gConf.mtx.Lock()
|
gConf.mtx.Lock()
|
||||||
|
gLog.setLevel(LogLevel(gConf.logLevel))
|
||||||
flag.Visit(func(f *flag.Flag) {
|
flag.Visit(func(f *flag.Flag) {
|
||||||
if f.Name == "sharebandwidth" {
|
if f.Name == "sharebandwidth" {
|
||||||
gConf.Network.ShareBandwidth = *shareBandwidth
|
gConf.Network.ShareBandwidth = *shareBandwidth
|
||||||
@@ -95,7 +96,21 @@ func main() {
|
|||||||
gConf.logLevel = *logLevel
|
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)
|
gLog.Println(LevelINFO, "openp2p start. version: ", OpenP2PVersion)
|
||||||
gConf.mtx.Unlock()
|
gConf.mtx.Unlock()
|
||||||
gConf.save()
|
gConf.save()
|
||||||
|
|||||||
+1
-1
@@ -10,7 +10,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
const OpenP2PVersion = "0.98.0"
|
const OpenP2PVersion = "0.98.1"
|
||||||
const ProducnName string = "openp2p"
|
const ProducnName string = "openp2p"
|
||||||
|
|
||||||
type openP2PHeader struct {
|
type openP2PHeader struct {
|
||||||
|
|||||||
Reference in New Issue
Block a user