mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-03 15:00:26 +08:00
增加edge-node accesslog命令,用来在本地查看访问日志
This commit is contained in:
@@ -22,7 +22,7 @@ func main() {
|
||||
app := apps.NewAppCmd().
|
||||
Version(teaconst.Version).
|
||||
Product(teaconst.ProductName).
|
||||
Usage(teaconst.ProcessName + " [-v|start|stop|restart|status|quit|test|reload|service|daemon|pprof]").
|
||||
Usage(teaconst.ProcessName + " [-v|start|stop|restart|status|quit|test|reload|service|daemon|pprof|accesslog]").
|
||||
Usage(teaconst.ProcessName + " [trackers|goman|conns|gc]").
|
||||
Usage(teaconst.ProcessName + " [ip.drop|ip.reject|ip.remove] IP")
|
||||
|
||||
@@ -258,6 +258,53 @@ func main() {
|
||||
}
|
||||
}
|
||||
})
|
||||
app.On("accesslog", func() {
|
||||
// local sock
|
||||
var tmpDir = os.TempDir()
|
||||
var sockFile = tmpDir + "/" + teaconst.AccessLogSockName
|
||||
_, err := os.Stat(sockFile)
|
||||
if err != nil {
|
||||
if !os.IsNotExist(err) {
|
||||
fmt.Println("[ERROR]" + err.Error())
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
var processSock = gosock.NewTmpSock(teaconst.ProcessName)
|
||||
reply, err := processSock.Send(&gosock.Command{
|
||||
Code: "accesslog",
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println("[ERROR]" + err.Error())
|
||||
return
|
||||
}
|
||||
if reply.Code == "error" {
|
||||
var errString = maps.NewMap(reply.Params).GetString("error")
|
||||
if len(errString) > 0 {
|
||||
fmt.Println("[ERROR]" + errString)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
conn, err := net.Dial("unix", sockFile)
|
||||
if err != nil {
|
||||
fmt.Println("[ERROR]start reading access log failed: " + err.Error())
|
||||
return
|
||||
}
|
||||
defer func() {
|
||||
_ = conn.Close()
|
||||
}()
|
||||
var buf = make([]byte, 1024)
|
||||
for {
|
||||
n, err := conn.Read(buf)
|
||||
if n > 0 {
|
||||
fmt.Print(string(buf[:n]))
|
||||
}
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
})
|
||||
app.Run(func() {
|
||||
node := nodes.NewNode()
|
||||
node.Start()
|
||||
|
||||
Reference in New Issue
Block a user