update log

This commit is contained in:
nikk gitanes
2021-08-23 20:27:17 +03:00
parent ebe547a566
commit 6775ded8ae
6 changed files with 28 additions and 15 deletions

View File

@@ -55,7 +55,7 @@ func main() {
settings.HttpAuth = params.HttpAuth settings.HttpAuth = params.HttpAuth
log.Init(params.LogPath, params.WebLogPath) log.Init(params.LogPath, params.WebLogPath)
fmt.Println("=========== START ===========") fmt.Println("=========== START ===========")
fmt.Println("Build Go version:", runtime.Version()) fmt.Println("TorrServer", version.Version+",", runtime.Version())
if params.HttpAuth { if params.HttpAuth {
log.TLogln("Use HTTP Auth file", settings.Path+"/accs.db") log.TLogln("Use HTTP Auth file", settings.Path+"/accs.db")
} }

View File

@@ -8,6 +8,7 @@ import (
"syscall" "syscall"
"server/log" "server/log"
"server/settings"
) )
func Preconfig(dkill bool) { func Preconfig(dkill bool) {
@@ -22,10 +23,12 @@ func Preconfig(dkill bool) {
go func() { go func() {
for s := range sigc { for s := range sigc {
if dkill { if dkill {
if (settings.BTsets.EnableDebug || s != syscall.SIGPIPE) {
log.TLogln("Signal catched:", s) log.TLogln("Signal catched:", s)
log.TLogln("To stop server, close it from web / api") log.TLogln("To stop server, close it from web / api")
} }
} }
}
}() }()
} }
} }

View File

@@ -50,7 +50,7 @@ func Init(path, webpath string) {
//https://stackoverflow.com/a/36140590 //https://stackoverflow.com/a/36140590
//fmt.Print(time.Now().UTC().Format("2006-01-02T15:04:05.999Z") + " TLOG " + string(bytes)) //fmt.Print(time.Now().UTC().Format("2006-01-02T15:04:05.999Z") + " TLOG " + string(bytes))
log.SetFlags(log.Ldate|log.Ltime|log.LUTC|log.Lmsgprefix) log.SetFlags(log.Ldate|log.Ltime|log.LUTC|log.Lmsgprefix)
log.SetPrefix("0000 TLOG ") log.SetPrefix("UTC0 TLOG ")
log.SetOutput(ff) log.SetOutput(ff)
} }
} }

View File

@@ -214,7 +214,7 @@ func SetSettings(set *sets.BTSets) {
} }
lockApi.Lock() lockApi.Lock()
defer lockApi.Unlock() defer lockApi.Unlock()
log.TLogln("drop all") log.TLogln("drop all torrents")
dropAllTorrent() dropAllTorrent()
time.Sleep(time.Second * 2) time.Sleep(time.Second * 2)
log.TLogln("disconect") log.TLogln("disconect")
@@ -222,6 +222,7 @@ func SetSettings(set *sets.BTSets) {
sets.SetBTSets(set) sets.SetBTSets(set)
log.TLogln("connect") log.TLogln("connect")
bts.Connect() bts.Connect()
time.Sleep(time.Second * 2)
log.TLogln("end set settings") log.TLogln("end set settings")
} }
@@ -231,11 +232,16 @@ func SetDefSettings() {
} }
lockApi.Lock() lockApi.Lock()
defer lockApi.Unlock() defer lockApi.Unlock()
log.TLogln("drop all torrents")
dropAllTorrent() dropAllTorrent()
time.Sleep(time.Second * 2)
log.TLogln("disconect")
bts.Disconnect() bts.Disconnect()
sets.SetDefault() sets.SetDefault()
log.TLogln("connect")
bts.Connect() bts.Connect()
time.Sleep(time.Second * 5) time.Sleep(time.Second * 2)
log.TLogln("end set default settings")
} }
func dropAllTorrent() { func dropAllTorrent() {

View File

@@ -48,11 +48,13 @@ func (t *Torrent) Stream(fileID int, req *http.Request, resp http.ResponseWriter
reader := t.NewReader(file) reader := t.NewReader(file)
host, port, err := net.SplitHostPort(req.RemoteAddr) host, port, err := net.SplitHostPort(req.RemoteAddr)
if sets.BTsets.EnableDebug {
if err != nil { if err != nil {
log.Println("Connect client") log.Println("Connect client")
} else { } else {
log.Println("Connect client", host, port) log.Println("Connect client", host, port)
} }
}
sets.SetViewed(&sets.Viewed{t.Hash().HexString(), fileID}) sets.SetViewed(&sets.Viewed{t.Hash().HexString(), fileID})
@@ -62,10 +64,12 @@ func (t *Torrent) Stream(fileID int, req *http.Request, resp http.ResponseWriter
http.ServeContent(resp, req, file.Path(), time.Unix(t.Timestamp, 0), reader) http.ServeContent(resp, req, file.Path(), time.Unix(t.Timestamp, 0), reader)
t.CloseReader(reader) t.CloseReader(reader)
if sets.BTsets.EnableDebug {
if err != nil { if err != nil {
log.Println("Disconnect client") log.Println("Disconnect client")
} else { } else {
log.Println("Disconnect client", host, port) log.Println("Disconnect client", host, port)
} }
}
return nil return nil
} }

View File

@@ -22,7 +22,7 @@ var (
) )
func Start(port string) { func Start(port string) {
log.TLogln("Start TorrServer", version.Version) log.TLogln("Start TorrServer")
ips := getLocalIps() ips := getLocalIps()
if len(ips) > 0 { if len(ips) > 0 {
log.TLogln("IP:", ips) log.TLogln("IP:", ips)