mirror of https://github.com/ehang-io/nps
add logs and version for sdk
parent
dfeaf523ee
commit
9993ce8131
|
@ -1041,7 +1041,12 @@ POST /auth/getauthkey
|
|||
如果您觉得nps对你有帮助,欢迎给予我们一定捐助,也是帮助nps更好的发展。
|
||||
## 致谢
|
||||
Thanks [jetbrains](https://www.jetbrains.com/?from=nps) for providing development tools for nps
|
||||

|
||||
|
||||
<html>
|
||||
<img src="https://ftp.bmp.ovh/imgs/2019/12/6435398b0c7402b1.png" width="300" align=center />
|
||||
</html>
|
||||
|
||||
|
||||
### 支付宝
|
||||

|
||||
### 微信
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
Loading…
Reference in New Issue