github.com/goki/mobile@v0.0.0-20230707090321-193544ec5700/internal/mobileinit/mobileinit_ios.go (about) 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 //go:build darwin && (arm || arm64) 6 // +build darwin 7 // +build arm arm64 8 9 package mobileinit 10 11 import ( 12 "log" 13 "unsafe" 14 ) 15 16 /* 17 #cgo CFLAGS: -x objective-c 18 #cgo LDFLAGS: -framework Foundation 19 20 #include <asl.h> 21 #include <stdlib.h> 22 23 void log_wrap(const char *logStr); 24 */ 25 import "C" 26 27 type aslWriter struct{} 28 29 func (aslWriter) Write(p []byte) (n int, err error) { 30 cstr := C.CString(string(p)) 31 C.log_wrap(cstr) 32 C.free(unsafe.Pointer(cstr)) 33 return len(p), nil 34 } 35 36 func init() { 37 log.SetOutput(aslWriter{}) 38 }