2014-09-25 23:21:02 +00:00
|
|
|
/* console.c
|
|
|
|
* Console log handler routines
|
|
|
|
*
|
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
|
|
|
* Copyright 1998 Gerald Combs
|
|
|
|
*
|
2018-04-30 07:47:58 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2014-09-25 23:21:02 +00:00
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
|
|
|
|
#include "epan/prefs.h"
|
2017-12-16 22:15:28 +00:00
|
|
|
#include "wsutil/time_util.h"
|
2014-09-25 23:21:02 +00:00
|
|
|
|
|
|
|
#include "console.h"
|
|
|
|
|
2021-06-08 01:46:52 +00:00
|
|
|
void
|
2021-06-10 21:13:11 +00:00
|
|
|
console_log_writer(const char *format, va_list ap,
|
2021-06-11 12:39:16 +00:00
|
|
|
const char *prefix, const char *domain _U_,
|
2021-06-10 21:13:11 +00:00
|
|
|
enum ws_log_level level _U_, void *ptr _U_)
|
2014-09-25 23:21:02 +00:00
|
|
|
{
|
2021-06-08 01:46:52 +00:00
|
|
|
gboolean fatal = level == LOG_LEVEL_ERROR;
|
2014-09-25 23:21:02 +00:00
|
|
|
#ifdef _WIN32
|
2021-06-08 01:46:52 +00:00
|
|
|
if (prefs.gui_console_open != console_open_never || fatal) {
|
2014-09-25 23:21:02 +00:00
|
|
|
/* the user wants a console or the application will terminate immediately */
|
|
|
|
create_console();
|
|
|
|
}
|
2021-06-08 01:46:52 +00:00
|
|
|
#else
|
|
|
|
(void)fatal;
|
|
|
|
#endif /* _WIN32 */
|
2019-03-14 17:55:28 +00:00
|
|
|
|
2021-06-10 21:13:11 +00:00
|
|
|
ws_log_fprint(stderr, format, ap, prefix);
|
2021-03-05 03:34:51 +00:00
|
|
|
|
2021-06-08 01:46:52 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
if (fatal) {
|
2019-03-14 17:55:28 +00:00
|
|
|
/* wait for a key press before the following error handler will terminate the program
|
|
|
|
this way the user at least can read the error message */
|
|
|
|
printf("\n\nPress any key to exit\n");
|
|
|
|
_getch();
|
2014-09-25 23:21:02 +00:00
|
|
|
}
|
2021-03-05 03:34:51 +00:00
|
|
|
#endif /* _WIN32 */
|
2014-09-25 23:21:02 +00:00
|
|
|
}
|