From ab223cffc9a12c60a33e429deb30624103f61f95 Mon Sep 17 00:00:00 2001 From: David Crawshaw Date: Wed, 19 Aug 2015 12:50:04 -0400 Subject: [PATCH] internal/mobileinit: send iOS logs to ASL Fixes golang/go#12194 Change-Id: I9ff771336996c19ca43da56e3f8944e79c980a2b Reviewed-on: https://go-review.googlesource.com/13703 Reviewed-by: Hyang-Ah Hana Kim --- internal/mobileinit/mobileinit_ios.go | 38 +++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 internal/mobileinit/mobileinit_ios.go diff --git a/internal/mobileinit/mobileinit_ios.go b/internal/mobileinit/mobileinit_ios.go new file mode 100644 index 0000000..e016049 --- /dev/null +++ b/internal/mobileinit/mobileinit_ios.go @@ -0,0 +1,38 @@ +// Copyright 2015 The Go 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 darwin +// +build arm arm64 + +package mobileinit + +import ( + "io" + "log" + "os" + "unsafe" +) + +/* +#include +#include + +void asl_log_wrap(const char *str) { + asl_log(NULL, NULL, ASL_LEVEL_NOTICE, str); +} +*/ +import "C" + +type aslWriter struct{} + +func (aslWriter) Write(p []byte) (n int, err error) { + cstr := C.CString(string(p)) + C.asl_log_wrap(cstr) + C.free(unsafe.Pointer(cstr)) + return len(p), nil +} + +func init() { + log.SetOutput(io.MultiWriter(os.Stderr, aslWriter{})) +}