Skip to content

Commit

Permalink
add logs and version for sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
cnlh committed Dec 7, 2019
1 parent dfeaf52 commit 9993ce8
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 6 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
### 微信
Expand Down
18 changes: 13 additions & 5 deletions cmd/npc/sdk.go
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 changes: 48 additions & 0 deletions lib/common/logs.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 9993ce8

Please sign in to comment.