diff --git a/inc/mpp_log.h b/inc/mpp_log.h index 2b38eab2..574b974f 100644 --- a/inc/mpp_log.h +++ b/inc/mpp_log.h @@ -17,6 +17,8 @@ #ifndef __MPP_LOG_H__ #define __MPP_LOG_H__ +#include + #include "rk_type.h" #include "mpp_log_def.h" @@ -88,6 +90,9 @@ void _mpp_log_l(int level, const char *tag, const char *fmt, const char *func, . void mpp_set_log_level(int level); int mpp_get_log_level(void); +typedef void (*MppLogCb)(void *ctx, int level, const char *tag, const char *fmt, const char *func, va_list args); +int mpp_set_log_callback(void *ctx, MppLogCb cb); + /* deprecated function */ void _mpp_log(const char *tag, const char *fmt, const char *func, ...); void _mpp_err(const char *tag, const char *fmt, const char *func, ...); diff --git a/osal/mpp_log.cpp b/osal/mpp_log.cpp index f9cec972..6a3ed530 100644 --- a/osal/mpp_log.cpp +++ b/osal/mpp_log.cpp @@ -17,7 +17,6 @@ #define MODULE_TAG "mpp_log" #include -#include #include #include "mpp_env.h" @@ -38,6 +37,8 @@ RK_U32 mpp_debug = 0; static const char *msg_log_warning = "log message is long\n"; static const char *msg_log_nothing = "\n"; static int mpp_log_level = MPP_LOG_INFO; +static MppLogCb mpp_log_ext_cb = NULL; +static void *mpp_log_ext_ctx = NULL; static void __mpp_log(os_log_callback func, const char *tag, const char *fmt, const char *fname, va_list args) @@ -114,6 +115,13 @@ void _mpp_log_l(int level, const char *tag, const char *fmt, const char *fname, va_list args; int log_level; + if (mpp_log_ext_cb) { + va_start(args, fname); + mpp_log_ext_cb(mpp_log_ext_ctx, level, tag, fmt, fname, args); + va_end(args); + return; + } + if (level <= MPP_LOG_UNKNOWN || level >= MPP_LOG_SILENT) return; @@ -154,6 +162,14 @@ int mpp_get_log_level(void) return level; } +int mpp_set_log_callback(void *ctx, MppLogCb cb) +{ + mpp_log_ext_cb = cb; + mpp_log_ext_ctx = ctx; + + return 0; +} + #ifdef __cplusplus } #endif