From 6b84ec54083da9911f5ad4816d0eb4f4745afad4 Mon Sep 17 00:00:00 2001 From: Jordan Augé Date: Mon, 7 Oct 2019 09:52:33 +0200 Subject: [HICN-298] Release new hICN app for Android MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I43adc62fadf00690b687078d739788dffdc5e566 Signed-off-by: Jordan Augé --- ctrl/facemgr/src/util/log.c | 60 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 56 insertions(+), 4 deletions(-) (limited to 'ctrl/facemgr/src/util/log.c') diff --git a/ctrl/facemgr/src/util/log.c b/ctrl/facemgr/src/util/log.c index 54943cf45..c1fc999ad 100644 --- a/ctrl/facemgr/src/util/log.c +++ b/ctrl/facemgr/src/util/log.c @@ -13,12 +13,16 @@ * limitations under the License. */ -#include "log.h" +#include #include #include #include +#ifdef __ANDROID__ +#include +#endif + log_conf_t log_conf = DEFAULT_LOG_CONF; #define FMT_DATETIME "%02d-%02d-%04d %02d:%02d:%02d" @@ -43,48 +47,96 @@ static char *timestamp(void) } void _log_va(int level, const char *fmt, va_list ap) -{ - char *prefix; - FILE *f = log_conf.log_file ? log_conf.log_file : stdout; +{ #if 0 if (!conf.log_system) return; #endif + char *prefix; + +#ifdef __ANDROID__ + int prio = -1; if (level > log_conf.log_level) return; switch (level) { case LOG_FATAL: + prio = ANDROID_LOG_FATAL; prefix = "FATAL: "; break; case LOG_ERROR: + prio = ANDROID_LOG_ERROR; prefix = "ERROR: "; break; case LOG_WARN: + prio = ANDROID_LOG_WARN; prefix = "WARNING: "; break; case LOG_INFO: + prio = ANDROID_LOG_INFO; prefix = ""; break; case LOG_DEBUG: + prio = ANDROID_LOG_DEBUG; prefix = "DEBUG: "; break; case LOG_TRACE: + prio = ANDROID_LOG_DEBUG; prefix = "TRACE: "; break; default: + prio = ANDROID_LOG_INFO; prefix = ""; break; } + if (log_conf.log_file) { + FILE *f = log_conf.log_file; + fprintf(f, "%s %s", timestamp(), prefix); + vfprintf(f, fmt, ap); + fprintf(f, "\n"); + } else { + __android_log_vprint(ANDROID_LOG_INFO, "HICN FACEMGR", fmt, ap); + } + +#else + + if (level > log_conf.log_level) + return; + + switch (level) { + case LOG_FATAL: + prefix = "FATAL: "; + break; + case LOG_ERROR: + prefix = "ERROR: "; + break; + case LOG_WARN: + prefix = "WARNING: "; + break; + case LOG_INFO: + prefix = ""; + break; + case LOG_DEBUG: + prefix = "DEBUG: "; + break; + case LOG_TRACE: + prefix = "TRACE: "; + break; + default: + prefix = ""; + break; + } + FILE *f = log_conf.log_file ? log_conf.log_file : stdout; fprintf(f, "%s %s", timestamp(), prefix); vfprintf(f, fmt, ap); fprintf(f, "\n"); #ifdef DEBUG fflush(f); #endif +#endif } void _log(int level, const char *fmt, ...) -- cgit 1.2.3-korg