1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21#define FOR_log
22#include "toys.h"
23
24GLOBALS(
25 char *t, *p;
26)
27
28void log_main(void)
29{
30 android_LogPriority pri = ANDROID_LOG_INFO;
31 char *s = toybuf;
32 int i;
33
34 if (TT.p) {
35 i = stridx("defisvw", tolower(*TT.p));
36 if (i==-1 || strlen(TT.p)!=1) error_exit("bad -p '%s'", TT.p);
37 pri = (android_LogPriority []){ANDROID_LOG_DEBUG, ANDROID_LOG_ERROR,
38 ANDROID_LOG_FATAL, ANDROID_LOG_INFO, ANDROID_LOG_SILENT,
39 ANDROID_LOG_VERBOSE, ANDROID_LOG_WARN}[i];
40 }
41 if (!TT.t) TT.t = "log";
42
43 for (i = 0; toys.optargs[i]; i++) {
44 if (i) *s++ = ' ';
45 if ((s-toybuf)+strlen(toys.optargs[i])>=1024) {
46 memcpy(s, toys.optargs[i], 1024-(s-toybuf));
47 toybuf[1024] = 0;
48 error_msg("log cut at 1024 bytes");
49
50 break;
51 }
52 s = stpcpy(s, toys.optargs[i]);
53 }
54
55 __android_log_write(pri, TT.t, toybuf);
56}
57