From 1ba7144578b8371842d9f6ef4159ff8c97932842 Mon Sep 17 00:00:00 2001
From: yanghui <yanghui@aiotlink.com>
Date: 星期五, 23 四月 2021 10:59:58 +0800
Subject: [PATCH] add para

---
 logc.go |   44 +++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 39 insertions(+), 5 deletions(-)

diff --git a/logc.go b/logc.go
index 8d35977..9a978df 100644
--- a/logc.go
+++ b/logc.go
@@ -2,6 +2,8 @@
 
 import (
 	"basic.com/valib/bhomebus.git"
+	"bytes"
+	"net/url"
 
 	"encoding/json"
 	"fmt"
@@ -42,17 +44,42 @@
 var (
 	msgChan chan []byte
 	bhSock *bhomebus.Socket
+	pubFn func(nodes []bhomebus.NetNode, topic string, data []byte, milliseconds int) int
 	ProcName string
 	ProcID string
 )
 
-func Init(sock *bhomebus.Socket, procId string, procName string) {
+func init() {
+
+}
+
+func InitBySock(sock *bhomebus.Socket, procId string, procName string) bool {
 	msgChan = make(chan []byte, 100)
 	ProcName = procName
 	ProcID = procId
 	bhSock = sock
+	if bhSock == nil {
+		return false
+	}
 
 	go saveLoop()
+
+	return true
+}
+
+func InitByPubFn(fn func(nodes []bhomebus.NetNode, topic string, data []byte, milliseconds int) int,
+				procId string, procName string) bool {
+	msgChan = make(chan []byte, 100)
+	ProcName = procName
+	ProcID = procId
+	pubFn = fn
+	if pubFn == nil {
+		return false
+	}
+
+	go saveLoop()
+
+	return true
 }
 
 func Save(level int, logType int, v ...interface{}) {
@@ -101,14 +128,21 @@
 		select {
 		case data := <- msgChan:
 			var nodes []bhomebus.NetNode
-			nodes = append(nodes, bhomebus.NetNode{
-				Key: 8,
-			})
-			bhSock.PubTimeout(nodes, LogSaveTopic, data, 1000)
+			nodes = append(nodes, bhomebus.NetNode{})
+			if bhSock != nil {
+				bhSock.PubTimeout(nodes, LogSaveTopic, data, 1000)
+			} else if pubFn != nil {
+				pubFn(nodes, LogSaveTopic, data, 1000)
+			} else {
+				fmt.Println("bhSock nil and pubFn nil")
+			}
+
 		default:
 			time.Sleep(10*time.Millisecond)
 		}
 	}
 }
 
+func Log(userName, method, path, contentType, module string, body *bytes.Buffer, values url.Values) {
 
+}

--
Gitblit v1.8.0