From 05ed76d4c04d97f0a9f42fc93dbf1d8eb9bd2c65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Valverde?= Date: Wed, 16 Jun 2021 01:07:37 +0100 Subject: [PATCH] wslog: Use plain format with "message" level Try out a simpler format with the default log level. Don't display process and file/function information with "message" level (experimental). --- CMakeLists.txt | 2 ++ ui/qt/main.cpp | 2 +- wsutil/wslog.c | 57 +++++++++++++++++++++++++++++--------------------- 3 files changed, 36 insertions(+), 25 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 540264bd0c..39720ab07c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -457,6 +457,8 @@ if( CMAKE_C_COMPILER_ID MATCHES "MSVC") # in pcap-stdinc.h when compiling C++ files, e.g. the Qt UI /DPSAPI_VERSION=1 /D_ALLOW_KEYWORD_MACROS + # https://stackoverflow.com/questions/37845163/what-is-the-purpose-of-microsofts-underscore-c-functions + /D_CRT_NONSTDC_NO_WARNINGS ) if(NOT WIRESHARK_TARGET_PLATFORM STREQUAL "win64") diff --git a/ui/qt/main.cpp b/ui/qt/main.cpp index c70109418b..588e078d44 100644 --- a/ui/qt/main.cpp +++ b/ui/qt/main.cpp @@ -977,7 +977,7 @@ int main(int argc, char *qt_argv[]) } wsApp->allSystemsGo(); - ws_log(LOG_DOMAIN_MAIN, LOG_LEVEL_INFO, "Wireshark is up and ready to go, elapsed time %.3fs\n", (float) (g_get_monotonic_time() - start_time) / 1000000); + ws_log(LOG_DOMAIN_MAIN, LOG_LEVEL_MESSAGE, "Wireshark is up and ready to go, elapsed time %.3fs", (float) (g_get_monotonic_time() - start_time) / 1000000); SimpleDialog::displayQueuedMessages(main_w); /* User could specify filename, or display filter, or both */ diff --git a/wsutil/wslog.c b/wsutil/wslog.c index d1cd117ec2..26a465ca04 100644 --- a/wsutil/wslog.c +++ b/wsutil/wslog.c @@ -17,6 +17,9 @@ #ifdef HAVE_UNISTD_H #include #endif +#ifdef _WIN32 +#include +#endif #include #include @@ -334,35 +337,41 @@ static void log_write_do_work(FILE *fp, gboolean use_color, const char *timestam const char *file, int line, const char *func, const char *user_format, va_list user_ap) { -#ifndef _WIN32 - fprintf(fp, " ** (%s:%ld) ", - registered_appname ? registered_appname : "PID", (long)getpid()); -#else - if (registered_appname) - fprintf(fp, " ** (%s) ", registered_appname); - else - fprintf(fp, " ** "); -#endif - - if (timestamp) - fputs(timestamp, fp); - const char *level_str = ws_log_level_to_string(level); + gboolean doextra = (level != LOG_LEVEL_MESSAGE); - if (strcmp(domain, LOG_DOMAIN_DEFAULT) != 0) - fprintf(fp, " [%s-%s]", domain, level_str); - else - fprintf(fp, " [%s]", level_str); + if (doextra) { + fprintf(fp, " ** (%s:%ld) ", registered_appname ? + registered_appname : "PID", (long)getpid()); + } + else { + fputs(" ** ", fp); + } - if (file && line >= 0) - fprintf(fp, " %s:%d", file, line); - else if (file) - fprintf(fp, " %s", file); + if (timestamp) { + fputs(timestamp, fp); + fputc(' ', fp); + } - fputs(" -- ", fp); + if (strcmp(domain, LOG_DOMAIN_DEFAULT) != 0) { + fprintf(fp, "[%s-%s] ", domain, level_str); + } + else { + fprintf(fp, "[%s] ", level_str); + } - if (func) - fprintf(fp, "%s%s()%s: " , color_on(use_color), func, color_off(use_color)); + if (doextra) { + if (file && line >= 0) { + fprintf(fp, "%s:%d ", file, line); + } + else if (file) { + fprintf(fp, "%s ", file); + } + fputs("-- ", fp); + if (func) { + fprintf(fp, "%s%s()%s: " , color_on(use_color), func, color_off(use_color)); + } + } vfprintf(fp, user_format, user_ap); fputc('\n', fp);