Skip to content

Commit

Permalink
chore: improve logging, add trace level logging (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
zshipko authored Oct 21, 2024
1 parent 249d7a6 commit 805e1b0
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion extism-pdk.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ EXTISM_IMPORT_ENV("log_warn")
extern void extism_log_warn(const ExtismHandle);
EXTISM_IMPORT_ENV("log_error")
extern void extism_log_error(const ExtismHandle);
EXTISM_IMPORT_ENV("log_trace")
extern void extism_log_trace(const ExtismHandle);
EXTISM_IMPORT_ENV("get_log_level")
extern int32_t extism_get_log_level();

EXTISM_IMPORT_ENV("input_offset")
extern ExtismHandle extism_input_offset(void);
Expand Down Expand Up @@ -134,8 +138,9 @@ static inline char *extism_load_input_sz_dup(size_t *outSize) {
ExtismHandle extism_alloc_buf_from_sz(const char *sz);

typedef enum {
ExtismLogInfo,
ExtismLogTrace,
ExtismLogDebug,
ExtismLogInfo,
ExtismLogWarn,
ExtismLogError,
} ExtismLog;
Expand Down Expand Up @@ -413,6 +418,10 @@ ExtismHandle extism_alloc_buf_from_sz(const char *sz) {

// Write to Extism log
void extism_log(const char *s, const size_t len, const ExtismLog level) {
if (level < extism_get_log_level()) {
return;
}

ExtismHandle buf = extism_alloc(len);
__extism_store(buf, s, len);
switch (level) {
Expand All @@ -428,6 +437,9 @@ void extism_log(const char *s, const size_t len, const ExtismLog level) {
case ExtismLogError:
extism_log_error(buf);
break;
case ExtismLogTrace:
extism_log_trace(buf);
break;
}
}

Expand Down

0 comments on commit 805e1b0

Please sign in to comment.