Browse Source

Expose API to set log level in embedder (#2907)

Expose API `void wasm_runtime_set_log_level(log_level_t level)`.
Enrico Loparco 2 years ago
parent
commit
6dbfeb25dd
2 changed files with 22 additions and 0 deletions
  1. 6 0
      core/iwasm/common/wasm_runtime_common.c
  2. 16 0
      core/iwasm/include/wasm_export.h

+ 6 - 0
core/iwasm/common/wasm_runtime_common.c

@@ -701,6 +701,12 @@ wasm_runtime_full_init(RuntimeInitArgs *init_args)
     return true;
 }
 
+void
+wasm_runtime_set_log_level(log_level_t level)
+{
+    bh_log_set_verbose_level(level);
+}
+
 bool
 wasm_runtime_is_running_mode_supported(RunningMode running_mode)
 {

+ 16 - 0
core/iwasm/include/wasm_export.h

@@ -212,6 +212,14 @@ typedef struct wasm_val_t {
 } wasm_val_t;
 #endif
 
+typedef enum {
+    WASM_LOG_LEVEL_FATAL = 0,
+    WASM_LOG_LEVEL_ERROR = 1,
+    WASM_LOG_LEVEL_WARNING = 2,
+    WASM_LOG_LEVEL_DEBUG = 3,
+    WASM_LOG_LEVEL_VERBOSE = 4
+} log_level_t;
+
 /**
  * Initialize the WASM runtime environment, and also initialize
  * the memory allocator with system allocator, which calls os_malloc
@@ -234,6 +242,14 @@ wasm_runtime_init(void);
 WASM_RUNTIME_API_EXTERN bool
 wasm_runtime_full_init(RuntimeInitArgs *init_args);
 
+/**
+ * Set the log level. To be called after the runtime is initialized. 
+ * 
+ * @param level the log level to set
+ */
+WASM_RUNTIME_API_EXTERN void
+wasm_runtime_set_log_level(log_level_t level);
+
 /**
  * Query whether a certain running mode is supported for the runtime
  *