From e9580e939b61eeadb3fd7b56a4914e482b5a06e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E6=B2=B3?= Date: Thu, 19 Dec 2019 00:46:22 +0800 Subject: [PATCH] print log when run with nps --- cmd/nps/nps.go | 12 ++++++++---- docs/run.md | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/cmd/nps/nps.go b/cmd/nps/nps.go index f4c771c..306da88 100644 --- a/cmd/nps/nps.go +++ b/cmd/nps/nps.go @@ -25,7 +25,7 @@ import ( ) var ( - level string + level string ) func main() { @@ -57,6 +57,12 @@ func main() { Description: "一款轻量级、功能强大的内网穿透代理服务器。支持tcp、udp流量转发,支持内网http代理、内网socks5代理,同时支持snappy压缩、站点保护、加密传输、多路复用、header修改等。支持web图形化管理,集成多用户模式。", Option: options, } + svcConfig.Arguments = append(svcConfig.Arguments, "service") + if len(os.Args) > 1 && os.Args[1] == "service" { + logs.SetLogger(logs.AdapterFile, `{"level":`+level+`,"filename":"`+logPath+`","daily":false,"maxlines":100000,"color":true}`) + } else { + logs.SetLogger(logs.AdapterConsole, `{"level":`+level+`,"color":true}`) + } if !common.IsWindows() { svcConfig.Dependencies = []string{ "Requires=network.target", @@ -69,8 +75,7 @@ func main() { logs.Error(err) return } - logs.SetLogger(logs.AdapterConsole, `{"level":`+level+`,"color":true}`) - if len(os.Args) > 1 { + if len(os.Args) > 1 && os.Args[1] != "service" { switch os.Args[1] { case "reload": daemon.InitDaemon("nps", common.GetRunPath(), common.GetTmpPath()) @@ -93,7 +98,6 @@ func main() { } return case "start", "restart", "stop", "uninstall": - logs.SetLogger(logs.AdapterFile, `{"level":`+level+`,"filename":"`+logPath+`","daily":false,"maxlines":100000,"color":true}`) err := service.Control(s, os.Args[1]) if err != nil { logs.Error("Valid actions: %q\n", service.ControlAction, err.Error()) diff --git a/docs/run.md b/docs/run.md index dea35dc..805e154 100644 --- a/docs/run.md +++ b/docs/run.md @@ -18,7 +18,7 @@ 停止和重启可用,stop和restart -**如果发现没有启动成功,可以使用`nps(.exe) debug`运行调试,或查看日志**(Windows日志文件位于当前运行目录下,linux和darwin位于/var/log/nps.log) +**如果发现没有启动成功,可以使用`nps(.exe) stop`,然后运行`nps.(exe)`运行调试,或查看日志**(Windows日志文件位于当前运行目录下,linux和darwin位于/var/log/nps.log) - 访问服务端ip:web服务端口(默认为8080) - 使用用户名和密码登陆(默认admin/123,正式使用一定要更改) - 创建客户端