Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce log clutter #4477

Open
wants to merge 1 commit into
base: v2.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions include/proxysql.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ int pkt_end(unsigned char *, unsigned int);
int pkt_com_query(unsigned char *, unsigned int);
enum MySQL_response_type mysql_response(unsigned char *, unsigned int);

__attribute__((__format__ (__printf__, 2, 3)))
void proxy_error_func(int errcode, const char *, ...);
__attribute__((__format__ (__printf__, 3, 4)))
void proxy_error_func(int errcode, int loglevel, const char *, ...);
void print_backtrace(void);
void proxy_info_(const char* msg, ...);

Expand Down
24 changes: 15 additions & 9 deletions include/proxysql_debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ extern int gdbg;
/*
#ifdef DEBUG
*/

// define the levels of logging messages
const int loglevel_error = 1;
const int loglevel_warning = 2;
const int loglevel_info = 3;

#define proxy_error(fmt, ...) \
do { \
time_t __timer; \
Expand All @@ -55,7 +61,7 @@ extern int gdbg;
time(&__timer); \
localtime_r(&__timer, &__tm_info); \
strftime(__buffer, 25, "%Y-%m-%d %H:%M:%S", &__tm_info); \
proxy_error_func(0, "%s %s:%d:%s(): [ERROR] " fmt, __buffer, __FILE__, __LINE__, __func__ , ## __VA_ARGS__); \
proxy_error_func(0, loglevel_error, "%s %s:%d:%s(): [ERROR] " fmt, __buffer, __FILE__, __LINE__, __func__ , ## __VA_ARGS__); \
} while(0)

#define proxy_error2(ecode, fmt, ...) \
Expand All @@ -66,7 +72,7 @@ extern int gdbg;
time(&__timer); \
localtime_r(&__timer, &__tm_info); \
strftime(__buffer, 25, "%Y-%m-%d %H:%M:%S", &__tm_info); \
proxy_error_func(ecode, "%s %s:%d:%s(): [ERROR] " fmt, __buffer, __FILE__, __LINE__, __func__ , ## __VA_ARGS__); \
proxy_error_func(ecode, loglevel_error, "%s %s:%d:%s(): [ERROR] " fmt, __buffer, __FILE__, __LINE__, __func__ , ## __VA_ARGS__); \
} while(0)

#define proxy_error_inline(fi, li, fu, fmt, ...) \
Expand All @@ -77,7 +83,7 @@ extern int gdbg;
time(&__timer); \
localtime_r(&__timer, &__tm_info); \
strftime(__buffer, 25, "%Y-%m-%d %H:%M:%S", &__tm_info); \
proxy_error_func(0, "%s %s:%d:%s(): [ERROR] " fmt, __buffer, fi, li, fu , ## __VA_ARGS__); \
proxy_error_func(0, loglevel_error, "%s %s:%d:%s(): [ERROR] " fmt, __buffer, fi, li, fu , ## __VA_ARGS__); \
} while(0)
/*
#else
Expand All @@ -104,7 +110,7 @@ extern int gdbg;
time(&__timer); \
__tm_info = localtime(&__timer); \
strftime(__buffer, 25, "%Y-%m-%d %H:%M:%S", __tm_info); \
proxy_error_func(0, "%s %s:%d:%s(): [WARNING] " fmt, __buffer, __FILE__, __LINE__, __func__ , ## __VA_ARGS__); \
proxy_error_func(0, loglevel_warning, "%s %s:%d:%s(): [WARNING] " fmt, __buffer, __FILE__, __LINE__, __func__ , ## __VA_ARGS__); \
} while(0)

#define proxy_warning2(ecode, fmt, ...) \
Expand All @@ -115,7 +121,7 @@ extern int gdbg;
time(&__timer); \
__tm_info = localtime(&__timer); \
strftime(__buffer, 25, "%Y-%m-%d %H:%M:%S", __tm_info); \
proxy_error_func(ecode, "%s %s:%d:%s(): [WARNING] " fmt, __buffer, __FILE__, __LINE__, __func__ , ## __VA_ARGS__); \
proxy_error_func(ecode, loglevel_warning, "%s %s:%d:%s(): [WARNING] " fmt, __buffer, __FILE__, __LINE__, __func__ , ## __VA_ARGS__); \
} while(0)

/*
Expand All @@ -141,7 +147,7 @@ extern int gdbg;
time(&__timer); \
__tm_info = localtime(&__timer); \
strftime(__buffer, 25, "%Y-%m-%d %H:%M:%S", __tm_info); \
proxy_error_func(0, "%s %s:%d:%s(): [INFO] " fmt, __buffer, __FILE__, __LINE__, __func__ , ## __VA_ARGS__); \
proxy_error_func(0, loglevel_info, "%s %s:%d:%s(): [INFO] " fmt, __buffer, __FILE__, __LINE__, __func__ , ## __VA_ARGS__); \
} while(0)

#define proxy_info2(ecode, fmt, ...) \
Expand All @@ -152,7 +158,7 @@ extern int gdbg;
time(&__timer); \
__tm_info = localtime(&__timer); \
strftime(__buffer, 25, "%Y-%m-%d %H:%M:%S", __tm_info); \
proxy_error_func(ecode, "%s %s:%d:%s(): [INFO] " fmt, __buffer, __FILE__, __LINE__, __func__ , ## __VA_ARGS__); \
proxy_error_func(ecode, loglevel_info, "%s %s:%d:%s(): [INFO] " fmt, __buffer, __FILE__, __LINE__, __func__ , ## __VA_ARGS__); \
} while(0)
#else
#define proxy_info(fmt, ...) \
Expand All @@ -163,7 +169,7 @@ extern int gdbg;
time(&__timer); \
__tm_info = localtime(&__timer); \
strftime(__buffer, 25, "%Y-%m-%d %H:%M:%S", __tm_info); \
proxy_error_func(0, "%s [INFO] " fmt , __buffer , ## __VA_ARGS__); \
proxy_error_func(0, loglevel_info, "%s [INFO] " fmt , __buffer , ## __VA_ARGS__); \
} while(0)

#define proxy_info2(fmt, ...) \
Expand All @@ -174,7 +180,7 @@ extern int gdbg;
time(&__timer); \
__tm_info = localtime(&__timer); \
strftime(__buffer, 25, "%Y-%m-%d %H:%M:%S", __tm_info); \
proxy_error_func(ecode, "%s [INFO] " fmt , __buffer , ## __VA_ARGS__); \
proxy_error_func(ecode, loglevel_info, "%s [INFO] " fmt , __buffer , ## __VA_ARGS__); \
} while(0)
#endif

Expand Down
1 change: 1 addition & 0 deletions include/proxysql_glovars.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class ProxySQL_GlobalVariables {
char *errorlog;
char *pid;
int restart_on_missing_heartbeats;
int console_logging_verbosity_level;
char * execute_on_exit_failure;
char * sqlite3_plugin;
char * web_interface_plugin;
Expand Down
8 changes: 6 additions & 2 deletions lib/debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,10 +331,11 @@ unordered_map<string, ProxySQL_messages_stats> umap_msg_stats {};
* Any other use of the function is UNSAFE. And will result in unespecified behavior.
* @param msgid The message id of the message to be logged, when non-zero, stats about the message are updated in
* 'umap_msg_stats'.
* @param loglevel The level of log entry (as per LOG_LEVEL_*)
* @param fmt The formatted string to be pass to 'vfprintf'.
* @param ... The variadic list of arguments to be passed to 'vfprintf'.
*/
void proxy_error_func(int msgid, const char *fmt, ...) {
void proxy_error_func(int msgid, int loglevel, const char *fmt, ...) {
va_list ap;
va_start(ap, fmt);

Expand Down Expand Up @@ -375,7 +376,10 @@ void proxy_error_func(int msgid, const char *fmt, ...) {
}
}

vfprintf(stderr, fmt, ap);
if (GloVars.console_logging_verbosity_level >= loglevel) {
vfprintf(stderr, fmt, ap);
}

va_end(ap);
};

Expand Down
10 changes: 10 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,7 @@ void ProxySQL_Main_process_global_variables(int argc, const char **argv) {
GloVars.parse(argc,argv);
GloVars.process_opts_pre();
GloVars.restart_on_missing_heartbeats = 10; // default
GloVars.console_logging_verbosity_level = loglevel_info; // output all logging entries to stderr by default
// alwasy try to open a config file
if (GloVars.confFile->OpenFile(GloVars.config_file) == true) {
GloVars.configfile_open=true;
Expand All @@ -493,6 +494,15 @@ void ProxySQL_Main_process_global_variables(int argc, const char **argv) {
GloVars.restart_on_missing_heartbeats=restart_on_missing_heartbeats;
}
}
if (root.exists("console_logging_verbosity_level")==true) {
// read console_logging_verbosity_level from config file
int console_logging_verbosity_level;
bool rc;
rc=root.lookupValue("console_logging_verbosity_level", console_logging_verbosity_level);
if (rc==true) {
GloVars.console_logging_verbosity_level=console_logging_verbosity_level;
}
}
if (root.exists("execute_on_exit_failure")==true) {
// restart_on_missing_heartbeats datadir from config file
string execute_on_exit_failure;
Expand Down