5 #include <android/log.h>
9 #define APP_NAME "andemo"
12 static void *thread_func(void *arg);
16 static int initialized;
18 int start_logger(void)
24 /* set stdout to line-buffered, and stderr to unbuffered */
25 setvbuf(stdout, 0, _IOLBF, 0);
26 setvbuf(stderr, 0, _IONBF, 0);
29 perror("failed to create logging pipe");
32 assert(pfd[0] > 2 && pfd[1] > 2);
34 /* redirect stdout & stderr to the write-end of the pipe */
38 /* start the logging thread */
39 if(pthread_create(&thr, 0, thread_func, 0) == -1) {
40 perror("failed to spawn logging thread");
47 static void *thread_func(void *arg)
52 __android_log_print(ANDROID_LOG_DEBUG, APP_NAME, "logger starting up...");
54 while((rdsz = read(pfd[0], buf, sizeof buf - 1)) > 0) {
55 if(buf[rdsz - 1] == '\n') {
59 __android_log_write(ANDROID_LOG_DEBUG, APP_NAME, buf);
62 __android_log_print(ANDROID_LOG_DEBUG, APP_NAME, "logger shutting down...");