blob: dadd5d0e8e26463e94a447a3531d73ef6d874abf [file] [log] [blame]
// Copyright 2015 The Vanadium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build android
package jni
// #include <android/log.h>
// #cgo LDFLAGS: -llog
import "C"
import (
"bytes"
"log"
"unsafe"
)
var ctag *C.char = C.CString("Go runtime")
func init() {
log.SetOutput(&androidWriter{})
}
type androidWriter struct {
buf []byte
}
func (aw *androidWriter) Write(p []byte) (n int, err error) {
n = len(p)
err = nil
for nlidx := bytes.IndexByte(p, '\n'); nlidx != -1; nlidx = bytes.IndexByte(p, '\n') {
aw.buf = append(aw.buf, p[:nlidx]...)
p = p[nlidx+1:]
aw.buf = append(aw.buf, 0)
cstr := (*C.char)(unsafe.Pointer(&aw.buf[0]))
C.__android_log_write(C.ANDROID_LOG_INFO, ctag, cstr)
aw.buf = aw.buf[:0]
}
aw.buf = append(aw.buf, p...)
return
}