-
Notifications
You must be signed in to change notification settings - Fork 4
/
log.go
68 lines (55 loc) · 978 Bytes
/
log.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
57
58
59
60
61
62
63
64
65
66
67
68
package asmcgocall
import (
"fmt"
"strings"
)
var Debug bool = false
func bytes(i interface{}) string {
var res int
switch i.(type) {
case int:
res = i.(int)
case uintptr:
res = int(i.(uintptr))
}
if res > 1 {
return "bytes"
} else {
return "byte"
}
}
type LogFormat byte
const (
LogFormatDefault = iota
LogFormatC
LogFormatGo
)
var logFormat LogFormat = LogFormatC
func SetLogFormat(logf LogFormat) {
logFormat = logf
}
func logf(str string, args ...interface{}) {
switch logFormat {
case LogFormatC:
if strings.Index(str, "__pad") != -1 {
return
}
for i, a := range args {
switch a.(type) {
case string:
args[i] = strings.ReplaceAll(args[i].(string), "_Ctype_", "")
}
}
case LogFormatGo:
if strings.Index(str, "__pad") != -1 {
return
}
for i, a := range args {
switch a.(type) {
case string:
args[i] = strings.ReplaceAll(args[i].(string), "_Ctype_", "C.")
}
}
}
fmt.Printf(str, args...)
}