mirror of
https://github.com/ehang-io/nps.git
synced 2025-07-03 04:53:50 +00:00
add logs and version for sdk
This commit is contained in:
parent
dfeaf523ee
commit
9993ce8131
@ -1041,7 +1041,12 @@ POST /auth/getauthkey
|
|||||||
如果您觉得nps对你有帮助,欢迎给予我们一定捐助,也是帮助nps更好的发展。
|
如果您觉得nps对你有帮助,欢迎给予我们一定捐助,也是帮助nps更好的发展。
|
||||||
## 致谢
|
## 致谢
|
||||||
Thanks [jetbrains](https://www.jetbrains.com/?from=nps) for providing development tools for 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
|
package main
|
||||||
|
|
||||||
import "C"
|
|
||||||
import (
|
import (
|
||||||
|
"C"
|
||||||
"github.com/astaxie/beego/logs"
|
"github.com/astaxie/beego/logs"
|
||||||
"github.com/cnlh/nps/client"
|
"github.com/cnlh/nps/client"
|
||||||
|
"github.com/cnlh/nps/lib/common"
|
||||||
|
"github.com/cnlh/nps/lib/version"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
|
||||||
logs.SetLogger(logs.AdapterFile, `{"filename":"npc.log","daily":false,"maxlines":100000,"color":true}`)
|
|
||||||
}
|
|
||||||
|
|
||||||
var status int
|
var status int
|
||||||
var closeBefore int
|
var closeBefore int
|
||||||
var cl *client.TRPClient
|
var cl *client.TRPClient
|
||||||
@ -48,6 +46,16 @@ func CloseClient() {
|
|||||||
cl.Close()
|
cl.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//export Version
|
||||||
|
func Version() *C.char {
|
||||||
|
return C.CString(version.VERSION)
|
||||||
|
}
|
||||||
|
|
||||||
|
func Logs() *C.char {
|
||||||
|
return C.CString(common.GetLogMsg())
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// Need a main function to make CGO compile package as C shared library
|
// Need a main function to make CGO compile package as C shared library
|
||||||
|
logs.SetLogger("store")
|
||||||
}
|
}
|
||||||
|
48
lib/common/logs.go
Normal file
48
lib/common/logs.go
Normal 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
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user