aboutsummaryrefslogtreecommitdiffstats
path: root/ui/console.c
blob: dd53635d9ce25c70a95fbfcf38600a4407e0dbf9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/* console.c
 * Console log handler routines
 *
 * Wireshark - Network traffic analyzer
 * By Gerald Combs <gerald@wireshark.org>
 * Copyright 1998 Gerald Combs
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

#include "config.h"

#include <stdio.h>


#include "epan/prefs.h"
#include "wsutil/time_util.h"
#include <wsutil/ws_assert.h>

#include "console.h"

void
console_log_writer(const char *domain, enum ws_log_level level,
                                   struct timespec timestamp,
                                   const char *file, int line, const char *func,
                                   const char *user_format, va_list user_ap,
                                   void *user_data _U_)
{
    gboolean fatal = level == LOG_LEVEL_ERROR;

#ifdef _WIN32
    if (prefs.gui_console_open != console_open_never || fatal) {
        /* the user wants a console or the application will terminate immediately */
        create_console();
    }
#else
    (void)fatal;
#endif /* _WIN32 */

    ws_log_console_writer(domain, level, timestamp, file, line, func,
                                user_format, user_ap);

#ifdef _WIN32
    if (fatal) {
        /* 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();
    }
#endif /* _WIN32 */
}