forked from allinurl/goaccess
-
Notifications
You must be signed in to change notification settings - Fork 0
/
error.c
102 lines (84 loc) · 2.24 KB
/
error.c
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/**
* error.c -- error handling
* Copyright (C) 2009-2014 by Gerardo Orellana <[email protected]>
* GoAccess - An Ncurses apache weblog analyzer & interactive viewer
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* A copy of the GNU General Public License is attached to this
* source distribution for its full text.
*
* Visit http://goaccess.prosoftcorp.com for new releases.
*/
#if HAVE_CONFIG_H
#include <config.h>
#endif
#ifdef HAVE_LIBNCURSESW
#ifdef __FreeBSD__
#include <ncurses.h>
#else
#include <ncursesw/curses.h>
#endif
#else
#include <ncurses.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include "error.h"
#include "commons.h"
static FILE *log_file;
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
void
error_handler (const char *func, const char *file, int line, const char *msg,
...)
{
va_list args;
(void) endwin ();
fprintf (stderr, "\nGoAccess - version %s - %s %s\n", GO_VERSION,
__DATE__, __TIME__);
fprintf (stderr, "\nAn error has occurred");
fprintf (stderr, "\nError occured at: %s - %s - %d", file, func, line);
fprintf (stderr, "\nMessage: ");
va_start (args, msg);
vfprintf (stderr, msg, args);
va_end (args);
fprintf (stderr, "\n\n");
exit (EXIT_FAILURE);
}
#pragma GCC diagnostic warning "-Wformat-nonliteral"
void
dbg_log_open (const char *path)
{
if (path != NULL) {
log_file = fopen (path, "w");
if (log_file == NULL)
return;
}
}
void
dbg_log_close (void)
{
if (log_file != NULL)
fclose (log_file);
}
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
void
dbg_fprintf (const char *fmt, ...)
{
va_list args;
if (!log_file)
return;
va_start (args, fmt);
vfprintf (log_file, fmt, args);
fflush (log_file);
va_end (args);
}
#pragma GCC diagnostic warning "-Wformat-nonliteral"