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"
|
2021-06-18 18:21:42 +00:00
|
|
|
#include <wsutil/ws_assert.h>
|
2014-09-25 23:21:02 +00:00
|
|
|
|
|
|
|
#include "console.h"
|
|
|
|
|
2021-06-08 01:46:52 +00:00
|
|
|
void
|
2021-06-14 18:53:59 +00:00
|
|
|
console_log_writer(const char *domain, enum ws_log_level level,
|
2021-12-15 13:25:11 +00:00
|
|
|
struct timespec timestamp,
|
2022-01-04 01:23:10 +00:00
|
|
|
const char *file, long line, const char *func,
|
2021-06-14 18:53:59 +00:00
|
|
|
const char *user_format, va_list user_ap,
|
|
|
|
void *user_data _U_)
|
2014-09-25 23:21:02 +00:00
|
|
|
{
|
2021-06-08 01:46:52 +00:00
|
|
|
gboolean fatal = level == LOG_LEVEL_ERROR;
|
2021-06-14 18:53:59 +00:00
|
|
|
|
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-12-02 16:33:45 +00:00
|
|
|
ws_log_console_writer(domain, level, timestamp, file, line, func,
|
|
|
|
user_format, user_ap);
|
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
|
|
|
}
|