-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdebug_func.go
56 lines (45 loc) · 1.08 KB
/
debug_func.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright 2017-2019 [email protected]. All rights reserved
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"crypto/tls"
"fmt"
"log"
)
/* four kinds of log functions:
1. No print
2. fmt print
3. log print
4. send to our private log server(see logServer)
*/
func nullPrintf(format string, args ...interface{}) {
}
func fmtPrintf(format string, args ...interface{}) {
fmt.Printf(format, args...)
}
func logPrintf(format string, args ...interface{}) {
log.Printf(format, args...)
}
var logFd *tls.Conn
var logServer string
func sendToLogServer(format string, args ...interface{}) {
if logFd == nil {
// has to explict declare err instead of shorthand otherwise global logFd is NULL
var err error = nil
logFd, err = tls.Dial("tcp", logServer, &tls.Config{InsecureSkipVerify: true})
if err != nil {
_ = logFd
return
}
}
fmt.Fprintf(logFd, format, args...)
}
func closeLogFd() {
if logFd != nil {
logFd.Close()
logFd = nil
}
}
// Set the debug Based on the above choices
var Debug = nullPrintf