| 1 |
// Copyright 2015 The Go Authors. All rights reserved. |
| 2 |
// Use of this source code is governed by a BSD-style |
| 3 |
// license that can be found in the LICENSE file. |
| 4 |
|
| 5 |
package mobileinit |
| 6 |
|
| 7 |
import ( |
| 8 |
"io" |
| 9 |
"log" |
| 10 |
"os" |
| 11 |
"unsafe" |
| 12 |
) |
| 13 |
|
| 14 |
/* |
| 15 |
#include <stdlib.h> |
| 16 |
#include <os/log.h> |
| 17 |
|
| 18 |
os_log_t create_os_log() { |
| 19 |
return os_log_create("org.golang.mobile", "os_log"); |
| 20 |
} |
| 21 |
|
| 22 |
void os_log_wrap(os_log_t log, const char *str) { |
| 23 |
os_log(log, "%s", str); |
| 24 |
} |
| 25 |
*/ |
| 26 |
import "C" |
| 27 |
|
| 28 |
type osWriter struct { |
| 29 |
w C.os_log_t |
| 30 |
} |
| 31 |
|
| 32 |
func (o osWriter) Write(p []byte) (n int, err error) { |
| 33 |
cstr := C.CString(string(p)) |
| 34 |
C.os_log_wrap(o.w, cstr) |
| 35 |
C.free(unsafe.Pointer(cstr)) |
| 36 |
return len(p), nil |
| 37 |
} |
| 38 |
|
| 39 |
func init() { |
| 40 |
log.SetOutput(io.MultiWriter(os.Stderr, osWriter{C.create_os_log()})) |
| 41 |
} |