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 if (asprintf(&format2
, "[%0*"PRIxPTR
"/%lx] %s %s: %s",
50 ptr_width
, p_item
->i_object_id
, p_item
->tid
, p_item
->psz_module
,
51 p_item
->psz_object_type
, format
) < 0)
55 prio
= ANDROID_LOG_INFO
;
58 prio
= ANDROID_LOG_ERROR
;
61 prio
= ANDROID_LOG_WARN
;
65 prio
= ANDROID_LOG_DEBUG
;
67 __android_log_vprint(prio
, "VLC", format2
, ap
);
71 static vlc_log_cb
Open(vlc_object_t
*obj
, void **sysp
)
73 int verbosity
= var_InheritInteger(obj
, "verbose");
78 verbosity
+= VLC_MSG_ERR
;
79 *sysp
= (void *)(uintptr_t)verbosity
;
81 return AndroidPrintMsg
;
85 set_shortname(N_("Android log"))
86 set_description(N_("Android log using logcat"))
87 set_category(CAT_ADVANCED
)
88 set_subcategory(SUBCAT_ADVANCED_MISC
)
89 set_capability("logger", 30)
90 set_callbacks(Open
, NULL
)