add logs and version for sdk

pull/298/head
刘河 2019-12-08 00:29:00 +08:00
parent dfeaf523ee
commit 9993ce8131
3 changed files with 67 additions and 6 deletions

View File

@ -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)
<html>
<img src="https://ftp.bmp.ovh/imgs/2019/12/6435398b0c7402b1.png" width="300" align=center />
</html>
### 支付宝
![image](https://github.com/cnlh/nps/blob/master/image/donation_zfb.png?raw=true)
### 微信

View File

@ -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")
}

48
lib/common/logs.go Normal file
View File

@ -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
}