diff --git a/README.md b/README.md index b08104e..5fb13c6 100644 --- a/README.md +++ b/README.md @@ -1041,7 +1041,12 @@ POST /auth/getauthkey 如果您觉得nps对你有帮助,欢迎给予我们一定捐助,也是帮助nps更好的发展。 ## 致谢 Thanks [jetbrains](https://www.jetbrains.com/?from=nps) for providing development tools for nps -![https://www.jetbrains.com/?from=nps](https://ftp.bmp.ovh/imgs/2019/12/6435398b0c7402b1.png) + + + + + + ### 支付宝 ![image](https://github.com/cnlh/nps/blob/master/image/donation_zfb.png?raw=true) ### 微信 diff --git a/cmd/npc/sdk.go b/cmd/npc/sdk.go index cf41af9..f26a3de 100644 --- a/cmd/npc/sdk.go +++ b/cmd/npc/sdk.go @@ -1,16 +1,14 @@ package main -import "C" import ( + "C" "github.com/astaxie/beego/logs" "github.com/cnlh/nps/client" + "github.com/cnlh/nps/lib/common" + "github.com/cnlh/nps/lib/version" "time" ) -func init() { - logs.SetLogger(logs.AdapterFile, `{"filename":"npc.log","daily":false,"maxlines":100000,"color":true}`) -} - var status int var closeBefore int var cl *client.TRPClient @@ -48,6 +46,16 @@ func CloseClient() { cl.Close() } +//export Version +func Version() *C.char { + return C.CString(version.VERSION) +} + +func Logs() *C.char { + return C.CString(common.GetLogMsg()) +} + func main() { // Need a main function to make CGO compile package as C shared library + logs.SetLogger("store") } diff --git a/lib/common/logs.go b/lib/common/logs.go new file mode 100644 index 0000000..477ac5b --- /dev/null +++ b/lib/common/logs.go @@ -0,0 +1,48 @@ +package common + +import ( + "github.com/astaxie/beego/logs" + "time" +) + +const MaxMsgLen = 5000 + +var logMsgs string + +func init() { + logs.Register("store", func() logs.Logger { + return new(StoreMsg) + }) +} + +func GetLogMsg() string { + return logMsgs +} + +type StoreMsg struct { +} + +func (lg *StoreMsg) Init(config string) error { + return nil +} + +func (lg *StoreMsg) WriteMsg(when time.Time, msg string, level int) error { + m := when.Format("2006-01-02 15:04:05") + " " + msg + "\r\n" + if len(logMsgs) > MaxMsgLen { + start := MaxMsgLen - len(m) + if start <= 0 { + start = MaxMsgLen + } + logMsgs = logMsgs[start:] + } + logMsgs += m + return nil +} + +func (lg *StoreMsg) Destroy() { + return +} + +func (lg *StoreMsg) Flush() { + return +}