Debug logging to disk

Minor changes in the implementation
pull/4149/head
René Cannaò 3 years ago
parent d4d2298a6f
commit cd623ec33b

@ -215,6 +215,8 @@ void proxysql_init_debug_prometheus_metrics();
/**
* @brief Set or unset if Admin has debugdb_disk fully initialized
*/
void proxysql_set_status_admin_debugdb_disk(bool status);
void proxysql_set_admin_debugdb_disk(SQLite3DB *_db);
void proxysql_set_admin_debug_output(unsigned int _do);
#endif

@ -5798,6 +5798,7 @@ ProxySQL_Admin::ProxySQL_Admin() :
#ifdef DEBUG
variables.debug=GloVars.global.gdbg;
debug_output = 1;
proxysql_set_admin_debug_output(debug_output);
#endif /* DEBUG */
last_p_memory_metrics_ts = 0;
@ -6100,7 +6101,7 @@ bool ProxySQL_Admin::init() {
debugdb_disk->execute("PRAGMA synchronous=0");
string cmd = "ATTACH DATABASE '" + debugdb_disk_path + "' AS debugdb_disk";
admindb->execute(cmd.c_str());
proxysql_set_status_admin_debugdb_disk(true);
proxysql_set_admin_debugdb_disk(debugdb_disk);
}
#endif /* DEBUG */
@ -6242,7 +6243,7 @@ void ProxySQL_Admin::admin_shutdown() {
delete monitordb;
delete statsdb_disk;
#ifdef DEBUG
proxysql_set_status_admin_debugdb_disk(false);
proxysql_set_admin_debugdb_disk(NULL);
delete debugdb_disk;
#endif
(*proxy_sqlite3_shutdown)();
@ -8467,6 +8468,7 @@ bool ProxySQL_Admin::set_variable(char *name, char *value) { // this is the pub
const auto fval = atoi(value);
if (fval > 0 && fval <= 3) {
debug_output = fval;
proxysql_set_admin_debug_output(debug_output);
return true;
} else {
return false;

@ -1,10 +1,9 @@
#include "proxysql.h"
#include "proxysql_atomic.h"
#include "proxysql_admin.h"
#include "sqlite3db.h"
#include "prometheus_helpers.h"
#include "gen_utils.h"
#include <set>
#include <cxxabi.h>
@ -28,9 +27,9 @@ using std::unordered_map;
#ifdef DEBUG
__thread unsigned long long pretime=0;
static pthread_mutex_t debug_mutex;
static bool debugdb_disk_init = false;
static SQLite3DB * debugdb_disk = NULL;
sqlite3_stmt *statement1=NULL;
extern ProxySQL_Admin *GloAdmin;
static unsigned int debug_output = 1;
#endif /* DEBUG */
/*
@ -133,7 +132,7 @@ void proxy_debug_func(enum debug_module module, int verbosity, int thr, const ch
unsigned long long curtime=realtime_time();
pthread_mutex_lock(&debug_mutex);
bool write_to_disk = false;
if (debugdb_disk_init == true && (GloAdmin->debug_output == 2 || GloAdmin->debug_output == 3)) {
if (debugdb_disk != NULL && (debug_output == 2 || debug_output == 3)) {
write_to_disk = true;
}
if (
@ -183,7 +182,7 @@ void proxy_debug_func(enum debug_module module, int verbosity, int thr, const ch
// fprintf(stderr, "%s", longdebugbuff);
}
#endif
if (debugdb_disk_init == false) {
if (debugdb_disk == NULL) {
// default behavior
if (longdebugbuff[0] != 0) {
fprintf(stderr, "%s", longdebugbuff);
@ -194,16 +193,14 @@ void proxy_debug_func(enum debug_module module, int verbosity, int thr, const ch
}
}
} else {
assert (GloAdmin != NULL);
SQLite3DB *db = GloAdmin->debugdb_disk;
assert(db != NULL);
SQLite3DB *db = debugdb_disk;
int rc = 0;
if (statement1==NULL) {
const char *a = "INSERT INTO debug_log (id, time, lapse, thread, file, line, funct, modnum, modname, verbosity, message, note, backtrace) VALUES (NULL, ?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, NULL, ?11)";
rc=db->prepare_v2(a, &statement1);
ASSERT_SQLITE_OK(rc, db);
}
if (GloAdmin->debug_output == 1 || GloAdmin->debug_output == 3) {
if (debug_output == 1 || debug_output == 3) {
// to stderr
if (longdebugbuff[0] != 0) {
fprintf(stderr, "%s", longdebugbuff);
@ -490,7 +487,11 @@ void init_debug_struct_from_cmdline() {
}
void proxysql_set_status_admin_debugdb_disk(bool status) {
debugdb_disk_init = status;
void proxysql_set_admin_debugdb_disk(SQLite3DB * _db) {
debugdb_disk = _db;
}
void proxysql_set_admin_debug_output(unsigned int _do) {
debug_output = _do;
}
#endif /* DEBUG */

Loading…
Cancel
Save