forked from osmocom/wireshark
Windows: Console log handler fixups.
Make sure that we always print log messages on Windows. External programs or scripts (including our test suite) might need to see log messages independent of our console settings. Make sure that we always use our log handler and that its stdout / stderr routing matches GLib's. Flush our log output, which is something that GLib's default handler sometimes doesn't do: https://bugzilla.gnome.org/show_bug.cgi?id=792432 Bug: 15605 Change-Id: I4b17f2cb9269b2c87c21835d82770dae93bbfa20 Reviewed-on: https://code.wireshark.org/review/32412 Petri-Dish: Gerald Combs <gerald@wireshark.org> Tested-by: Petri Dish Buildbot Reviewed-by: Gerald Combs <gerald@wireshark.org>
This commit is contained in:
parent
3b2204e127
commit
14796eb04a
27
ui/console.c
27
ui/console.c
|
@ -27,7 +27,7 @@ console_log_handler(const char *log_domain, GLogLevelFlags log_level,
|
|||
time_t curr;
|
||||
struct tm *today;
|
||||
const char *level;
|
||||
|
||||
FILE *stream = stderr;
|
||||
|
||||
/* ignore log message, if log_level isn't interesting based
|
||||
upon the console log preferences.
|
||||
|
@ -47,11 +47,8 @@ console_log_handler(const char *log_domain, GLogLevelFlags log_level,
|
|||
/* the user wants a console or the application will terminate immediately */
|
||||
create_console();
|
||||
}
|
||||
if (get_has_console()) {
|
||||
/* For some unknown reason, the above doesn't appear to actually cause
|
||||
anything to be sent to the standard output, so we'll just splat the
|
||||
message out directly, just to make sure it gets out. */
|
||||
#endif
|
||||
|
||||
switch(log_level & G_LOG_LEVEL_MASK) {
|
||||
case G_LOG_LEVEL_ERROR:
|
||||
level = "Err ";
|
||||
|
@ -67,9 +64,11 @@ console_log_handler(const char *log_domain, GLogLevelFlags log_level,
|
|||
break;
|
||||
case G_LOG_LEVEL_INFO:
|
||||
level = "Info";
|
||||
stream = stdout;
|
||||
break;
|
||||
case G_LOG_LEVEL_DEBUG:
|
||||
level = "Dbg ";
|
||||
stream = stdout;
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "unknown log_level %d\n", log_level);
|
||||
|
@ -82,16 +81,17 @@ console_log_handler(const char *log_domain, GLogLevelFlags log_level,
|
|||
today = localtime(&curr);
|
||||
guint64 microseconds = create_timestamp();
|
||||
if (today != NULL) {
|
||||
fprintf(stderr, "%02d:%02d:%02d.%03" G_GUINT64_FORMAT " %8s %s %s\n",
|
||||
fprintf(stream, "%02d:%02d:%02d.%03" G_GUINT64_FORMAT " %8s %s %s\n",
|
||||
today->tm_hour, today->tm_min, today->tm_sec,
|
||||
microseconds % 1000000 / 1000,
|
||||
log_domain != NULL ? log_domain : "",
|
||||
level, message);
|
||||
} else {
|
||||
fprintf(stderr, "Time not representable %8s %s %s\n",
|
||||
fprintf(stream, "Time not representable %8s %s %s\n",
|
||||
log_domain != NULL ? log_domain : "",
|
||||
level, message);
|
||||
}
|
||||
fflush(stream);
|
||||
#ifdef _WIN32
|
||||
if(log_level & G_LOG_LEVEL_ERROR) {
|
||||
/* wait for a key press before the following error handler will terminate the program
|
||||
|
@ -99,19 +99,6 @@ console_log_handler(const char *log_domain, GLogLevelFlags log_level,
|
|||
printf("\n\nPress any key to exit\n");
|
||||
_getch();
|
||||
}
|
||||
} else {
|
||||
/* XXX - on UN*X, should we just use g_log_default_handler()?
|
||||
We want the error messages to go to the standard output;
|
||||
on macOS, that will cause them to show up in various
|
||||
per-user logs accessible through Console (details depend
|
||||
on whether you're running 10.0 through 10.4 or running
|
||||
10.5 and later), and, on other UN*X desktop environments,
|
||||
if they don't show up in some form of console log, that's
|
||||
a deficiency in that desktop environment. (Too bad
|
||||
Windows doesn't set the standard output and error for
|
||||
GUI apps to something that shows up in such a log.) */
|
||||
g_log_default_handler(log_domain, log_level, message, user_data);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -121,7 +121,10 @@ create_console(void)
|
|||
return;
|
||||
}
|
||||
|
||||
if (!has_console) {
|
||||
if (has_console) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Are the standard input, output, and error invalid handles? */
|
||||
must_redirect_stdin = needs_redirection(STD_INPUT_HANDLE);
|
||||
must_redirect_stdout = needs_redirection(STD_OUTPUT_HANDLE);
|
||||
|
@ -198,7 +201,6 @@ do a FreeConsole() first. */
|
|||
|
||||
/* Well, we have a console now. */
|
||||
has_console = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -223,18 +225,6 @@ get_console_wait(void)
|
|||
return console_wait;
|
||||
}
|
||||
|
||||
void
|
||||
set_has_console(gboolean set_has_console)
|
||||
{
|
||||
has_console = set_has_console;
|
||||
}
|
||||
|
||||
gboolean
|
||||
get_has_console(void)
|
||||
{
|
||||
return has_console;
|
||||
}
|
||||
|
||||
void
|
||||
set_stdin_capture(gboolean set_stdin_capture)
|
||||
{
|
||||
|
|
|
@ -40,13 +40,6 @@ void set_console_wait(gboolean console_wait);
|
|||
*/
|
||||
gboolean get_console_wait(void);
|
||||
|
||||
/** Set has console. GTK+ only.
|
||||
* @param has_console set/no set has_console
|
||||
*/
|
||||
void set_has_console(gboolean has_console);
|
||||
|
||||
gboolean get_has_console(void);
|
||||
|
||||
/** Set stdin capture.
|
||||
* @param console_wait set/no stdin_capture
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue