-
Notifications
You must be signed in to change notification settings - Fork 645
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Forward log level to custom vprintf #3070
Forward log level to custom vprintf #3070
Conversation
1508155
to
8e80eda
Compare
8e80eda
to
1a00803
Compare
core/shared/utils/bh_log.c
Outdated
@@ -51,7 +51,7 @@ bh_log(LogLevel log_level, const char *file, int line, const char *fmt, ...) | |||
os_printf("%s, line %d, ", file, line); | |||
|
|||
va_start(ap, fmt); | |||
os_vprintf(fmt, ap); | |||
os_vprintf(log_level, fmt, ap); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@eloparco this change introduces lots of code changes, and it makes the code structure a little strange, the platform layer seems to rely on the shared/util layer, and the prototype of os_vprintf is inconsistent with vprintf.
Per my understanding, you want to take control the log dump in your code, how about introducing another macro BH_VLOG like BH_VPRINTF, and call it when it is defined:
va_start(ap, fmt);
#if defined(BH_VLOG)
BH_VLOG(log_level, fmt, ap);
#else
os_vprintf(fmt, ap);
#endif
Or just defined BH_LOG to replace bh_log function:
#ifndef BH_LOG
void
bh_log(LogLevel log_level, const char *file, int line, const char *fmt, ...)
{
...
}
#endif
and in bh_log.h
#ifndef BH_LOG
void
bh_log(LogLevel log_level, const char *file, int line, const char *fmt, ...);
#else
void
BH_LOG(LogLevel log_level, const char *file, int line, const char *fmt, ...);
#define bh_log BH_LOG
#endif
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tried that just to make sure, but it doesn't allow to forward the wasm output, coming from os_printf
,
err = wasmtime_ssp_fd_write(exec_env, curfds, fd, ciovec_begin, iovs_len, |
printf("calling into WASM function: %s\n", __FUNCTION__); |
os_printf
but not bh_log
).What I mean is, overriding
bh_log
only allows to take control of the runtime output, not the wasm one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you define both BH_LOG and BH_VPRINTF? It will forward both bh_log and os_printf.
Rather than making ad-hoc changes to unblock some usecases, I'd rather take a step back and refine how do we log in WAMR in general. I think we already have solid foundations to improve logging - we have a bunch of macros ( So in high level we'd have something like: typedef void (*bh_log_listener)(int level, int line, const char* file, const char *message, void *ud); // and other fields like timestamp or whatever we think is appropriate
void bh_log_register_listener(bh_log_listener, void *ud);
void bh_log_default_listener(int level, int line, const char *file, const char *message, void *_ud)
{
printf(....);
} So the @wenyongh let me know your thoughts. |
@loganek using a listener (or callback) is good to me, but I have two concerns: void bh_log_default_listener(int level, const char *file, int line, const char *fmt, va_list ap, void *user_data) another is whether it can meet the requirement from @eloparco, he wants to forward the log of |
The prototype was just an example, we can tune it. It was mainly just to present a high-level concept
I'd separate |
But os_printf and bh_log are difference, bh_log outputs more info, e.g. timestamp and thread id, and some developers may feel that os_printf is more convenient since sometimes we are not sure what we should call for bh_log - LOG_ERROR, LOG_WARNING, LOG_DEBUG or LOG_VERBOSE. |
I see why using Having said that, I feel like this is a separate discussion, independent on the goal that @eloparco is trying to achieve here. I'd keep |
build-scripts/config_common.cmake
Outdated
@@ -338,6 +338,9 @@ endif () | |||
if (DEFINED WAMR_BH_VPRINTF) | |||
add_definitions (-DBH_VPRINTF=${WAMR_BH_VPRINTF}) | |||
endif () | |||
if (DEFINED WAMR_BH_LOG) | |||
add_definitions (-DBH_LOG=1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest to be similar with WAMR_BH_VPRINTF:
if (DEFINED WAMR_BH_LOG)
add_defintions (-DBH_LOG=${WAMR_BH_LOG})
endif ()
So we only introduce macro BH_LOG to the code, and can use it as a flag to control the code, and developer can define the function with the name he wants.
In bh_log.h:
#ifndef BH_LOG
void
bh_log(LogLevel log_level, const char *file, int line, const char *fmt, ...);
#else
void
BH_LOG(uint32 log_level, const char *file, int line, const char *fmt, ...);
#define bh_log BH_LOG
#endif
We can also use WASM_LOG, e.g. add_defintions (-DWASM_LOG=${WAMR_BH_LOG})
, but it seems that BH_LOG is better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, good point, updated
samples/basic/build.sh
Outdated
@@ -21,7 +21,7 @@ echo "#####################build basic project" | |||
cd ${CURR_DIR} | |||
mkdir -p cmake_build | |||
cd cmake_build | |||
cmake .. -DCMAKE_BUILD_TYPE=Debug | |||
cmake .. -DCMAKE_BUILD_TYPE=Debug -DWAMR_BH_VPRINTF=my_vprintf -DWAMR_BH_LOG=1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about -DWAMR_BH_LOG=my_log
1bc6618
to
41e2acc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
…#3070) Follow-up on bytecodealliance#2907. The log level is needed in the host embedder to better integrate with the embedder's logger. Allow the developer to customize his bh_log callback with `cmake -DWAMR_BH_LOG=<log_callback>`, and update sample/basic to show the usage.
Follow-up on #2907.
The log level is needed in the embedded to better integrate with the embedder's logger.