MXS-1652 Add possibility to log SQL statements
With the flag --debug=enable-statement-logging it is now possible to instruct MaxScale to log all SQL statements it sends to the servers. The format of the logged string looks like: notice : SQL(127.0.0.1): 0, "SELECT ..." First the fixed string "SQL", followed by the server address in parenthesis followed by the actual return value of mysql_query(), followed by the statement itself. The "SQL" string makes the lines easy to grep for and having the return value before the statement makes it easier to spot since the length of the return value string does not wary much, but the length of the statements do wary a lot.
This commit is contained in:
@ -32,6 +32,21 @@
|
||||
#include <maxscale/debug.h>
|
||||
#include <maxscale/log_manager.h>
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
struct THIS_UNIT
|
||||
{
|
||||
bool log_statements; // Should all statements sent to server be logged?
|
||||
};
|
||||
|
||||
static THIS_UNIT this_unit =
|
||||
{
|
||||
false
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Calculate the length of a length-encoded integer in bytes
|
||||
*
|
||||
@ -221,6 +236,19 @@ int mxs_mysql_query(MYSQL* conn, const char* query)
|
||||
rc = mysql_query(conn, query);
|
||||
}
|
||||
|
||||
if (this_unit.log_statements)
|
||||
{
|
||||
const char* host;
|
||||
if (mariadb_get_info(conn, MARIADB_CONNECTION_HOST, &host) != 0)
|
||||
{
|
||||
// No idea about the host, but let's use something that looks like
|
||||
// an IP-address as a placeholder.
|
||||
host = "0.0.0.0";
|
||||
}
|
||||
|
||||
MXS_NOTICE("SQL(%s): %d, \"%s\"", host, rc, query);
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
@ -368,3 +396,13 @@ void mxs_mysql_set_server_version(MYSQL* mysql, SERVER* server)
|
||||
server_set_version(server, version_string, version);
|
||||
}
|
||||
}
|
||||
|
||||
void mxs_mysql_set_log_statements(bool enable)
|
||||
{
|
||||
this_unit.log_statements = enable;
|
||||
}
|
||||
|
||||
bool mxs_mysql_get_log_statements()
|
||||
{
|
||||
return this_unit.log_statements;
|
||||
}
|
||||
|
Reference in New Issue
Block a user