github.com/shranet/mobile@v0.0.0-20200814083559-5702cdcd481b/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  // +build darwin
     6  // +build arm arm64
     7  
     8  package mobileinit
     9  
    10  import (
    11  	"io"
    12  	"log"
    13  	"os"
    14  	"unsafe"
    15  )
    16  
    17  /*
    18  #include <asl.h>
    19  #include <stdlib.h>
    20  
    21  void asl_log_wrap(const char *str) {
    22  	asl_log(NULL, NULL, ASL_LEVEL_NOTICE, "%s", str);
    23  }
    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.asl_log_wrap(cstr)
    32  	C.free(unsafe.Pointer(cstr))
    33  	return len(p), nil
    34  }
    35  
    36  func init() {
    37  	log.SetOutput(io.MultiWriter(os.Stderr, aslWriter{}))
    38  }