diff options
author | 2019-10-07 09:52:33 +0200 | |
---|---|---|
committer | 2019-10-07 15:55:42 +0200 | |
commit | 6b84ec54083da9911f5ad4816d0eb4f4745afad4 (patch) | |
tree | e4296ebb218fff02dc0bbea73ce1c8d12aba7bcc /ctrl/facemgr/src/util/log.c | |
parent | 85a791ac2cdd35d79c00141e748b4c68fbdafb0d (diff) |
[HICN-298] Release new hICN app for Android
Change-Id: I43adc62fadf00690b687078d739788dffdc5e566
Signed-off-by: Jordan Augé <jordan.auge+fdio@cisco.com>
Diffstat (limited to 'ctrl/facemgr/src/util/log.c')
-rw-r--r-- | ctrl/facemgr/src/util/log.c | 60 |
1 files changed, 56 insertions, 4 deletions
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 <hicn/util/log.h> #include <stdarg.h> #include <stdlib.h> #include <stdio.h> +#ifdef __ANDROID__ +#include <android/log.h> +#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, ...) |