blob: a7a8370c5b2e457ce3c2bac731c41b589a197afa (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
/* log.c - Log to logcat.
*
* Copyright 2016 The Android Open Source Project
USE_LOG(NEWTOY(log, "<1p:t:", TOYFLAG_USR|TOYFLAG_SBIN))
config LOG
bool "log"
depends on TOYBOX_ON_ANDROID
default y
help
usage: log [-p PRI] [-t TAG] MESSAGE...
Logs message to logcat.
-p use the given priority instead of INFO:
d: DEBUG e: ERROR f: FATAL
i: INFO v: VERBOSE w: WARN
-t use the given tag instead of "log"
*/
#define FOR_log
#include "toys.h"
#if defined(__ANDROID__)
#include <android/log.h>
#endif
GLOBALS(
char *tag;
char *pri;
)
void log_main(void)
{
#if defined(__ANDROID__)
android_LogPriority pri = ANDROID_LOG_INFO;
int i;
if (TT.pri) {
if (strlen(TT.pri) != 1) TT.pri = "?";
switch (tolower(*TT.pri)) {
case 'd': pri = ANDROID_LOG_DEBUG; break;
case 'e': pri = ANDROID_LOG_ERROR; break;
case 'f': pri = ANDROID_LOG_FATAL; break;
case 'i': pri = ANDROID_LOG_INFO; break;
case 's': pri = ANDROID_LOG_SILENT; break;
case 'v': pri = ANDROID_LOG_VERBOSE; break;
case 'w': pri = ANDROID_LOG_WARN; break;
case '*': pri = ANDROID_LOG_DEFAULT; break;
default: error_exit("bad -p '%s'", TT.pri);
}
}
if (!TT.tag) TT.tag = "log";
for (i = 0; toys.optargs[i]; i++) {
if (i > 0) xstrncat(toybuf, " ", sizeof(toybuf));
xstrncat(toybuf, toys.optargs[i], sizeof(toybuf));
}
__android_log_write(pri, TT.tag, toybuf);
#endif
}
|