From 44477782d8e10109657a4107b050066bd33a39d2 Mon Sep 17 00:00:00 2001 From: Reuben Dunnington Date: Sun, 17 Sep 2023 20:29:59 -0700 Subject: [PATCH 1/2] logging: move parens to be in front of function --- src/platform/native_debug.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/platform/native_debug.c b/src/platform/native_debug.c index acdae4d..c5a2bad 100644 --- a/src/platform/native_debug.c +++ b/src/platform/native_debug.c @@ -60,7 +60,7 @@ void platform_log_push(oc_log_output* output, if(isatty(fd)) { fprintf(output->f, - "%s%s:%s %s() in %s:%i: ", + "%s%s:%s %s in %s():%i: ", OC_LOG_FORMATS[level], OC_LOG_HEADINGS[level], OC_LOG_FORMAT_STOP, @@ -71,7 +71,7 @@ void platform_log_push(oc_log_output* output, else { fprintf(output->f, - "%s: %s() in %s:%i: ", + "%s: %s in %s():%i: ", OC_LOG_HEADINGS[level], function, file, -- 2.25.1 From 116e614ab67c01d0907053ca7787d52a7d72f1d7 Mon Sep 17 00:00:00 2001 From: Martin Fouilleul Date: Mon, 18 Sep 2023 12:17:36 +0200 Subject: [PATCH 2/2] Keep log format as "function() in file:line: msg", but pass the arguments in consistent order between the host and guest app. --- src/platform/native_debug.c | 6 +++--- src/platform/orca_debug.c | 8 ++++---- src/platform/platform_debug.c | 2 +- src/runtime.c | 14 +++++++------- src/wasmbind/core_api.json | 10 +++++----- 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/platform/native_debug.c b/src/platform/native_debug.c index c5a2bad..0c804f0 100644 --- a/src/platform/native_debug.c +++ b/src/platform/native_debug.c @@ -45,8 +45,8 @@ oc_log_output* OC_LOG_DEFAULT_OUTPUT = &oc_logDefaultOutput; void platform_log_push(oc_log_output* output, oc_log_level level, - const char* file, const char* function, + const char* file, int line, const char* fmt, va_list ap) @@ -60,7 +60,7 @@ void platform_log_push(oc_log_output* output, if(isatty(fd)) { fprintf(output->f, - "%s%s:%s %s in %s():%i: ", + "%s%s:%s %s() in %s:%i: ", OC_LOG_FORMATS[level], OC_LOG_HEADINGS[level], OC_LOG_FORMAT_STOP, @@ -71,7 +71,7 @@ void platform_log_push(oc_log_output* output, else { fprintf(output->f, - "%s: %s in %s():%i: ", + "%s: %s() in %s:%i: ", OC_LOG_HEADINGS[level], function, file, diff --git a/src/platform/orca_debug.c b/src/platform/orca_debug.c index 3d0daf3..3a2f267 100644 --- a/src/platform/orca_debug.c +++ b/src/platform/orca_debug.c @@ -50,18 +50,18 @@ static oc_log_output oc_logDefaultOutput = { .kind = ORCA_LOG_OUTPUT_CONSOLE }; oc_log_output* OC_LOG_DEFAULT_OUTPUT = &oc_logDefaultOutput; void ORCA_IMPORT(oc_bridge_log)(oc_log_level level, - int fileLen, - const char* file, int functionLen, const char* function, + int fileLen, + const char* file, int line, int msgLen, const char* msg); void platform_log_push(oc_log_output* output, oc_log_level level, - const char* file, const char* function, + const char* file, int line, const char* fmt, va_list ap) @@ -76,7 +76,7 @@ void platform_log_push(oc_log_output* output, oc_str8 string = oc_str8_list_join(scratch.arena, ctx.list); - oc_bridge_log(level, strlen(file), file, strlen(function), function, line, oc_str8_ip(string)); + oc_bridge_log(level, strlen(function), function, strlen(file), file, line, oc_str8_ip(string)); oc_scratch_end(scratch); } diff --git a/src/platform/platform_debug.c b/src/platform/platform_debug.c index 435e65a..70da1db 100644 --- a/src/platform/platform_debug.c +++ b/src/platform/platform_debug.c @@ -28,8 +28,8 @@ void oc_log_set_level(oc_log_level level) void platform_log_push(oc_log_output* output, oc_log_level level, - const char* file, const char* function, + const char* file, int line, const char* fmt, va_list ap); diff --git a/src/runtime.c b/src/runtime.c index 9d2d3d7..d2928af 100644 --- a/src/runtime.c +++ b/src/runtime.c @@ -134,10 +134,10 @@ void oc_bridge_clipboard_set_string(oc_wasm_str8 value) } void oc_bridge_log(oc_log_level level, - int fileLen, - char* file, int functionLen, char* function, + int fileLen, + char* file, int line, int msgLen, char* msg) @@ -179,14 +179,14 @@ void oc_bridge_log(oc_log_level level, } char* payload = (char*)entry + sizeof(log_entry); - entry->file.len = fileLen; - entry->file.ptr = payload; - payload += entry->file.len; - entry->function.len = functionLen; entry->function.ptr = payload; payload += entry->function.len; + entry->file.len = fileLen; + entry->file.ptr = payload; + payload += entry->file.len; + entry->msg.len = msgLen; entry->msg.ptr = payload; payload += entry->msg.len; @@ -203,8 +203,8 @@ void oc_bridge_log(oc_log_level level, oc_list_push_back(&debug->logEntries, &entry->listElt); oc_log_ext(level, - file, function, + file, line, "%.*s\n", msgLen, diff --git a/src/wasmbind/core_api.json b/src/wasmbind/core_api.json index a8ae953..b3a7471 100644 --- a/src/wasmbind/core_api.json +++ b/src/wasmbind/core_api.json @@ -5,16 +5,16 @@ "ret": {"name": "void", "tag": "v"}, "args": [ {"name": "level", "type": {"name": "oc_log_level", "tag": "i"}}, - {"name": "fileLen", - "type": {"name": "int", "tag": "i"}}, - {"name": "file", - "type": {"name": "char*", "tag": "p"}, - "len": {"count": "fileLen"}}, {"name": "functionLen", "type": {"name": "int", "tag": "i"}}, {"name": "function", "type": {"name": "char*", "tag": "p"}, "len": {"count": "functionLen"}}, + {"name": "fileLen", + "type": {"name": "int", "tag": "i"}}, + {"name": "file", + "type": {"name": "char*", "tag": "p"}, + "len": {"count": "fileLen"}}, {"name": "line", "type": {"name": "int", "tag": "i"}}, {"name": "msgLen", -- 2.25.1