forked from remogatto/mandala
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlog_android.go
More file actions
43 lines (36 loc) · 793 Bytes
/
log_android.go
File metadata and controls
43 lines (36 loc) · 793 Bytes
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
// +build android
package mandala
// #include <android/log.h>
// #cgo LDFLAGS: -llog
import "C"
import (
"bytes"
"log"
"unsafe"
)
const (
// The default logcat tag for the framework
MandalaLogcatTag = "Mandala"
)
func init() {
log.SetOutput(AndroidWriter{Tag: MandalaLogcatTag})
}
type AndroidWriter struct {
buf []byte
Tag string
}
func (w AndroidWriter) Write(p []byte) (n int, err error) {
ctag := C.CString(w.Tag)
n = len(p)
err = nil
for nlidx := bytes.IndexByte(p, '\n'); nlidx != -1; nlidx = bytes.IndexByte(p, '\n') {
w.buf = append(w.buf, p[:nlidx]...)
p = p[nlidx+1:]
w.buf = append(w.buf, 0)
cstr := (*C.char)(unsafe.Pointer(&w.buf[0]))
C.__android_log_write(C.ANDROID_LOG_INFO, ctag, cstr)
w.buf = w.buf[:0]
}
w.buf = append(w.buf, p...)
return
}