add log function

This commit is contained in:
haidy 2018-12-29 01:44:48 +08:00
parent 6c6a4fe4e3
commit 85ebd0cb62
2 changed files with 67 additions and 2 deletions

View File

@ -1,10 +1,14 @@
package main
/*
*/
typedef void (*LogListener) (const char* log);
extern void setLogListener(LogListener l);
*/
import "C"
import (
"os"
"github.com/fatedier/frp/cmd/frpc/sub"
"github.com/fatedier/frp/cmd/frps/frps"
"github.com/fatedier/frp/utils/version"
@ -44,9 +48,14 @@ func Version() string {
}
func main() {
// frpsPath := os.Args[2]
frpsPath := os.Args[2]
// RunFrps(C.CString(frpsPath))
// TestFrps(C.CString(frpsPath))
println(frpsPath)
logLog()
RunFrps(C.CString(frpsPath))
c := make(chan bool)
<-c
}

56
cmd/macFrp/log.go Normal file
View File

@ -0,0 +1,56 @@
package main
/*
#include <stdio.h>
typedef void (*LogListener)(const char* log);
LogListener logListener;
void setLogListener(LogListener l) {
logListener = l;
}
void callback(const char* log) {
if (logListener) {
logListener(log);
}
}
void cListener(const char* log) {
printf("%s", log);
}
void testLog() {
setLogListener(cListener);
}
*/
import "C"
import (
"time"
"github.com/fatedier/frp/utils/log"
)
var l logForMacListener
type logForMacListener struct {
log.LogListener
}
func (l *logForMacListener) Log(log string) {
C.callback(C.CString(log))
}
func (l *logForMacListener) Location() string {
location, _ := time.LoadLocation("Local")
return location.String()
}
func init() {
l = logForMacListener{}
log.AppendListener(&l)
}
func logLog() {
C.testLog()
println(C.logListener)
}