aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2016-06-21 15:32:42 -0500
committerRob Landley <rob@landley.net>2016-06-21 15:32:42 -0500
commit3b051985b3c4787c8e323d41e2833c0278a13e20 (patch)
tree235171d8300aadf42c64cdf1d50c341ed2ef6aef
parent57dafe3915339090c6233cc82025adf116ddf667 (diff)
downloadtoybox-3b051985b3c4787c8e323d41e2833c0278a13e20.tar.gz
new Android toy: log
-rw-r--r--toys/android/log.c63
1 files changed, 63 insertions, 0 deletions
diff --git a/toys/android/log.c b/toys/android/log.c
new file mode 100644
index 00000000..a7a8370c
--- /dev/null
+++ b/toys/android/log.c
@@ -0,0 +1,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
+}