github.com/ethereumproject/go-ethereum@v5.5.2+incompatible/cmd/geth/library_android.go (about) 1 // Copyright 2015 The go-ethereum Authors 2 // This file is part of go-ethereum. 3 // 4 // go-ethereum is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // go-ethereum is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with go-ethereum. If not, see <http://www.gnu.org/licenses/>. 16 17 // Contains specialized code for running Geth on Android. 18 19 package main 20 21 // #include <android/log.h> 22 // #cgo LDFLAGS: -llog 23 import "C" 24 import ( 25 "bufio" 26 "os" 27 ) 28 29 func init() { 30 // Redirect the standard output and error to logcat 31 oldStdout, oldStderr := os.Stdout, os.Stderr 32 33 outRead, outWrite, _ := os.Pipe() 34 errRead, errWrite, _ := os.Pipe() 35 36 os.Stdout = outWrite 37 os.Stderr = errWrite 38 39 go func() { 40 scanner := bufio.NewScanner(outRead) 41 for scanner.Scan() { 42 line := scanner.Text() 43 C.__android_log_write(C.ANDROID_LOG_INFO, C.CString("Stdout"), C.CString(line)) 44 oldStdout.WriteString(line + "\n") 45 } 46 }() 47 48 go func() { 49 scanner := bufio.NewScanner(errRead) 50 for scanner.Scan() { 51 line := scanner.Text() 52 C.__android_log_write(C.ANDROID_LOG_INFO, C.CString("Stderr"), C.CString(line)) 53 oldStderr.WriteString(line + "\n") 54 } 55 }() 56 }