Commit a8d492c9 authored by Thomas Guillem's avatar Thomas Guillem Committed by Jean-Baptiste Kempf

android: convert Android logger to module

Signed-off-by: Jean-Baptiste Kempf's avatarJean-Baptiste Kempf <jb@videolan.org>
parent f9d5f255
......@@ -15,3 +15,10 @@ libsd_journal_plugin_la_LIBADD = $(SYSTEMD_LIBS)
if HAVE_SYSTEMD
logger_LTLIBRARIES += libsd_journal_plugin.la
endif
libandroid_logger_plugin_la_SOURCES = logger/android.c
libandroid_logger_plugin_la_CFLAGS = $(AM_CFLAGS)
libandroid_logger_plugin_la_LIBADD = -llog
if HAVE_ANDROID
logger_LTLIBRARIES += libandroid_logger_plugin.la
endif
/*****************************************************************************
* android.c: Android logger using logcat
*****************************************************************************
* Copyright © 2015 VLC authors and VideoLAN
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifndef __ANDROID__
#error __ANDROID__ not defined
#endif
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <android/log.h>
#include <stdarg.h>
#include <stdio.h>
#include <vlc_common.h>
#include <vlc_plugin.h>
static const int ptr_width = 2 * /* hex digits */ sizeof (uintptr_t);
static void AndroidPrintMsg(void *d, int type, const vlc_log_t *p_item,
const char *format, va_list ap)
{
int prio;
char *format2;
int canc = vlc_savecancel();
if (asprintf(&format2, "[%0*"PRIxPTR"] %s %s: %s",
ptr_width, p_item->i_object_id, p_item->psz_module,
p_item->psz_object_type, format) < 0)
return;
switch (type) {
case VLC_MSG_INFO:
prio = ANDROID_LOG_INFO;
break;
case VLC_MSG_ERR:
prio = ANDROID_LOG_ERROR;
break;
case VLC_MSG_WARN:
prio = ANDROID_LOG_WARN;
break;
default:
case VLC_MSG_DBG:
prio = ANDROID_LOG_DEBUG;
}
__android_log_vprint(prio, "VLC", format2, ap);
free(format2);
vlc_restorecancel(canc);
}
static vlc_log_cb Open(vlc_object_t *obj, void **sysp)
{
VLC_UNUSED(obj);
VLC_UNUSED(sysp);
return AndroidPrintMsg;
}
vlc_module_begin()
set_shortname(N_("Android log"))
set_description(N_("Android log using logcat"))
set_category(CAT_ADVANCED)
set_subcategory(SUBCAT_ADVANCED_MISC)
set_capability("logger", 30)
set_callbacks(Open, NULL)
vlc_module_end ()
......@@ -43,10 +43,6 @@
#include <vlc_modules.h>
#include "../libvlc.h"
#ifdef __ANDROID__
#include <android/log.h>
#endif
struct vlc_logger_t
{
VLC_COMMON_MEMBERS
......@@ -205,43 +201,6 @@ static void Win32DebugOutputMsg (void* d, int type, const vlc_log_t *p_item,
}
#endif
#ifdef __ANDROID__
static void AndroidPrintMsg (void *d, int type, const vlc_log_t *p_item,
const char *format, va_list ap)
{
int verbose = (intptr_t)d;
int prio;
if (verbose < 0 || verbose < (type - VLC_MSG_ERR))
return;
int canc = vlc_savecancel ();
char *format2;
if (asprintf (&format2, "[%0*"PRIxPTR"] %s %s: %s",
ptr_width, p_item->i_object_id, p_item->psz_module,
p_item->psz_object_type, format) < 0)
return;
switch (type) {
case VLC_MSG_INFO:
prio = ANDROID_LOG_INFO;
break;
case VLC_MSG_ERR:
prio = ANDROID_LOG_ERROR;
break;
case VLC_MSG_WARN:
prio = ANDROID_LOG_WARN;
break;
default:
case VLC_MSG_DBG:
prio = ANDROID_LOG_DEBUG;
}
__android_log_vprint (prio, "VLC", format2, ap);
free (format2);
vlc_restorecancel (canc);
}
#endif
typedef struct vlc_log_early_t
{
struct vlc_log_early_t *next;
......@@ -403,11 +362,7 @@ int vlc_LogInit(libvlc_int_t *vlc)
module_t *module = vlc_module_load(logger, "logger", NULL, false,
vlc_logger_load, logger, &cb, &sys);
if (module == NULL)
#ifdef __ANDROID__
cb = AndroidPrintMsg, sys = NULL;
#else
cb = vlc_vaLogDiscard;
#endif
vlc_rwlock_wrlock(&logger->lock);
if (logger->log == vlc_vaLogEarly)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment