Commit 99eeaee7 authored by Chuck Bell's avatar Chuck Bell

Merge with main prior to push for BUG#12929345.

parents 1e7f0637 cee822ca
......@@ -22,6 +22,24 @@ template <> void error_log_print<error_log_level::INFO>(const char *fmt, ...);
template <> void error_log_print<error_log_level::WARNING>(const char *fmt, ...);
template <> void error_log_print<error_log_level::ERROR>(const char *fmt, ...);
/**
Option indicating desired level of logging. Values:
0 - no logging
1 - log only error messages
2 - additionally log warnings
3 - additionally log info notes
4 - also log debug messages
Value of this option should be taken into account in the
implementation of error_log_vprint() function (see
log_client.cc).
Note: No error or debug messages are logged in production code
(see logging macros in common.h).
*/
int opt_auth_win_log_level= 2;
/** Connection class **************************************************/
......
......@@ -41,13 +41,15 @@ struct error_log_level
typedef enum {INFO, WARNING, ERROR} type;
};
extern "C" int opt_auth_win_log_level;
unsigned int get_log_level(void);
void set_log_level(unsigned int);
/*
If DEBUG_ERROR_LOG is defined then error logging happens only
in debug-copiled code. Otherwise ERROR_LOG() expands to
error_log_print() even in production code. Note that in client
plugin, error_log_print() will print nothing if opt_auth_win_clinet_log
is 0.
error_log_print() even in production code.
Note: Macro ERROR_LOG() can use printf-like format string like this:
......@@ -57,8 +59,6 @@ struct error_log_level
to fprintf() (see error_log_vprint() function).
*/
extern "C" int opt_auth_win_client_log;
#if defined(DEBUG_ERROR_LOG) && defined(DBUG_OFF)
#define ERROR_LOG(Level, Msg) do {} while (0)
#else
......@@ -67,7 +67,7 @@ extern "C" int opt_auth_win_client_log;
void error_log_vprint(error_log_level::type level,
const char *fmt, va_list args);
const char *fmt, va_list args);
template <error_log_level::type Level>
void error_log_print(const char *fmt, ...)
......@@ -96,7 +96,7 @@ const char* get_last_error_message(Error_message_buf);
#define DBUG_PRINT_DO(Keyword, Msg) \
do { \
if (2 > opt_auth_win_client_log) break; \
if (4 > get_log_level()) break; \
fprintf(stderr, "winauth: %s: ", Keyword); \
debug_msg Msg; \
} while (0)
......
......@@ -323,13 +323,13 @@ int win_auth_handshake_client(MYSQL_PLUGIN_VIO *vio, MYSQL *mysql)
int opt_val= opt ? atoi(opt) : 0;
if (opt && !opt_val)
{
if (!strncasecmp("on", opt, 2)) opt_val= 1;
if (!strncasecmp("yes", opt, 3)) opt_val= 1;
if (!strncasecmp("true", opt, 4)) opt_val= 1;
if (!strncasecmp("debug", opt, 5)) opt_val= 2;
if (!strncasecmp("dbug", opt, 4)) opt_val= 2;
if (!strncasecmp("on", opt, 2)) opt_val= 2;
if (!strncasecmp("yes", opt, 3)) opt_val= 2;
if (!strncasecmp("true", opt, 4)) opt_val= 2;
if (!strncasecmp("debug", opt, 5)) opt_val= 4;
if (!strncasecmp("dbug", opt, 4)) opt_val= 4;
}
opt_auth_win_client_log= opt_val;
set_log_level(opt_val);
}
ERROR_LOG(INFO, ("Authentication handshake for account %s", mysql->user));
......
......@@ -16,36 +16,32 @@
#include <my_global.h>
#include "common.h"
/**
This option is set in win_auth_handshake_client() function
in handshake_client.cc.
Values:
0 - no logging
1 - log error/warning/info messages
2 - also log debug messages
Note: No error or debug messages are logged in production code
(see logging macros in common.h).
*/
int opt_auth_win_client_log= 0;
// Client-side logging function
void error_log_vprint(error_log_level::type level,
const char *fmt, va_list args)
{
if (0 == opt_auth_win_client_log)
return;
const char *level_string= "";
int log_level= get_log_level();
switch (level)
{
case error_log_level::INFO: level_string= "Note"; break;
case error_log_level::WARNING: level_string= "Warning"; break;
case error_log_level::ERROR: level_string= "ERROR"; break;
case error_log_level::INFO:
if (3 > log_level)
return;
level_string= "Note";
break;
case error_log_level::WARNING:
if (2 > log_level)
return;
level_string= "Warning";
break;
case error_log_level::ERROR:
if (1 > log_level)
return;
level_string= "ERROR";
break;
}
fprintf(stderr, "Windows Authentication Plugin %s: ", level_string);
......@@ -53,3 +49,17 @@ void error_log_vprint(error_log_level::type level,
fputc('\n', stderr);
fflush(stderr);
}
// Trivial implementation of log-level setting storage.
void set_log_level(unsigned int level)
{
opt_auth_win_log_level= level;
}
unsigned int get_log_level(void)
{
return opt_auth_win_log_level;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment