-
Notifications
You must be signed in to change notification settings - Fork 12
/
log.cpp
78 lines (59 loc) · 1.89 KB
/
log.cpp
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
/**************************************************************
log.cpp - Simple logging for Switchres
---------------------------------------------------------
Switchres Modeline generation engine for emulation
License GPL-2.0+
Copyright 2010-2021 Chris Kennedy, Antonio Giner,
Alexandre Wodarczyk, Gil Delescluse
**************************************************************/
#include "log.h"
enum log_verbosity { NONE, SR_ERROR, SR_INFO, SR_DEBUG };
static log_verbosity log_level = SR_INFO;
void log_dummy(const char *, ...) {}
LOG_VERBOSE log_verbose = &log_dummy;
LOG_INFO log_info = &log_dummy;
LOG_ERROR log_error = &log_dummy;
/*
* These bakup pointers are here to let the user modify the log level at runtime
* We can't sadly unify a log function and test the log level to test if it should
* output a log, because it would imply frewriting log_ functions with va_args
* and wouldn't work with emulators log functions anymore
*/
LOG_VERBOSE log_verbose_bak = &log_dummy;
LOG_INFO log_info_bak = &log_dummy;
LOG_ERROR log_error_bak = &log_dummy;
void set_log_verbose(void *func_ptr)
{
if (log_level >= SR_DEBUG)
log_verbose = (LOG_VERBOSE)func_ptr;
log_verbose_bak = (LOG_VERBOSE)func_ptr;
}
void set_log_info(void *func_ptr)
{
if (log_level >= SR_INFO)
log_info = (LOG_INFO)func_ptr;
log_info_bak = (LOG_INFO)func_ptr;
}
void set_log_error(void *func_ptr)
{
if (log_level >= SR_ERROR)
log_error = (LOG_ERROR)func_ptr;
log_error_bak = (LOG_ERROR)func_ptr;
}
void set_log_verbosity(int level)
{
// Keep the log in the enum bounds
if (level < NONE)
level = NONE;
if(level > SR_DEBUG)
level = SR_DEBUG;
log_error = &log_dummy;
log_info = &log_dummy;
log_verbose = &log_dummy;
if (level >= SR_ERROR)
log_error = log_error_bak;
if (level >= SR_INFO)
log_info = log_info_bak;
if (level >= SR_DEBUG)
log_verbose = log_verbose_bak;
}