1 /*****************************************************************************
2 * android.c: Android logger using logcat
3 *****************************************************************************
4 * Copyright © 2015 VLC authors and VideoLAN
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2.1 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19 *****************************************************************************/
22 #error __ANDROID__ not defined
29 #include <android/log.h>
34 #include <vlc_common.h>
35 #include <vlc_plugin.h>
37 static const int ptr_width = 2 * /* hex digits */ sizeof (uintptr_t);
39 static void AndroidPrintMsg(void *opaque, int type, const vlc_log_t *p_item,
40 const char *format, va_list ap)
44 int verbose = (intptr_t)opaque;
49 int canc = vlc_savecancel();
51 if (asprintf(&format2, "[%0*"PRIxPTR"] %s %s: %s",
52 ptr_width, p_item->i_object_id, p_item->psz_module,
53 p_item->psz_object_type, format) < 0)
57 prio = ANDROID_LOG_INFO;
60 prio = ANDROID_LOG_ERROR;
63 prio = ANDROID_LOG_WARN;
67 prio = ANDROID_LOG_DEBUG;
69 __android_log_vprint(prio, "VLC", format2, ap);
71 vlc_restorecancel(canc);
74 static vlc_log_cb Open(vlc_object_t *obj, void **sysp)
76 int verbosity = var_InheritInteger(obj, "verbose");
81 *sysp = (void *)(uintptr_t)verbosity;
83 return AndroidPrintMsg;
87 set_shortname(N_("Android log"))
88 set_description(N_("Android log using logcat"))
89 set_category(CAT_ADVANCED)
90 set_subcategory(SUBCAT_ADVANCED_MISC)
91 set_capability("logger", 30)
92 set_callbacks(Open, NULL)