Remove all traces of logfile_t

The earlier log file based approach for enabling and disabling
messages has now been completely replaced with the syslog priority
based approach.

Similarly as with log files before it is now possible to enable
and disable a log priority for a particular session, even though
it apparently has not been used much.

The local test-programs of the logging has got minimal attention
only to make them compile. They should get an overhaul as they did
not work before either.
This commit is contained in:
Johan Wikman 2015-11-23 19:02:46 +02:00
parent 910ddb99fd
commit a8535f42af
15 changed files with 334 additions and 489 deletions

View File

@ -116,13 +116,6 @@ static struct
false // use_stdout
};
/**
* Variable holding the enabled logfiles information.
* Used from log users to check enabled logs prior calling
* actual library calls such as skygw_log_write.
*/
int lm_enabled_logfiles_bitmask = 0;
/**
* Variable holding the enabled priorities information.
* Used from logging macros.
@ -139,7 +132,7 @@ __thread log_info_t tls_log_info = {0, 0};
* Global counter for each log file type. It indicates for how many sessions
* each log type is currently enabled.
*/
ssize_t log_ses_count[LOGFILE_LAST] = {0};
ssize_t log_ses_count[LOG_DEBUG] = {0};
/**
* BUFSIZ comes from the system. It equals with block size or
@ -271,7 +264,6 @@ struct logmanager
skygw_chk_t lm_chk_top;
#endif
bool lm_enabled;
int lm_enabled_logfiles;
simple_mutex_t lm_mutex;
size_t lm_nlinks;
/** fwr_logmes is for messages from log clients */
@ -326,7 +318,6 @@ static bool logmanager_init_nomutex(const char* ident,
const char* logdir,
log_target_t target);
static void logmanager_done_nomutex(void);
static bool logmanager_is_valid_id(logfile_id_t id);
static int logmanager_write_log(int priority,
enum log_flush flush,
@ -388,9 +379,6 @@ static bool logmanager_init_nomutex(const char* ident,
goto return_succ;
}
lm->lm_enabled_logfiles |= LOGFILE_ERROR;
lm->lm_enabled_logfiles |= LOGFILE_MESSAGE;
fn = &lm->lm_fnames_conf;
fw = &lm->lm_filewriter;
fn->fn_state = UNINIT;
@ -417,7 +405,7 @@ static bool logmanager_init_nomutex(const char* ident,
/**
* Set global variable
*/
lm_enabled_logfiles_bitmask = lm->lm_enabled_logfiles;
lm_enabled_priorities_bitmask = MXS_LOG_ERR | MXS_LOG_NOTICE;
/**
* Initialize filewriter data and open the log file
@ -586,43 +574,6 @@ static logfile_t* logmanager_get_logfile(logmanager_t* lmgr)
return lf;
}
/**
* Returns true if the id log file id is valid.
*
* NOTE: Log manager is assumed to exist.
*
* @param id The id of a log file.
*
*/
static bool logmanager_is_valid_id(logfile_id_t id)
{
bool rval = false;
CHK_LOGMANAGER(lm);
if ((id >= LOGFILE_FIRST) && (id <= LOGFILE_LAST))
{
rval = true;
}
else
{
const char ERRSTR[] = "Invalid logfile id argument.";
int err = logmanager_write_log(LOG_ERR,
LOG_FLUSH_YES,
0, sizeof(ERRSTR), ERRSTR);
if (err != 0)
{
fprintf(stderr, "Writing to logfile %s failed.\n", STRLOGID(LOGFILE_ERROR));
}
}
return rval;
}
/**
* Finds write position from block buffer for log string and writes there.
*
@ -1179,50 +1130,6 @@ static blockbuf_t* blockbuf_init()
return bb;
}
static int skygw_log_enable(logfile_id_t id)
{
bool rval = -1;
if (logmanager_register(true))
{
CHK_LOGMANAGER(lm);
lm->lm_enabled_logfiles |= id;
/**
* Set global variable
*/
lm_enabled_logfiles_bitmask = lm->lm_enabled_logfiles;
logmanager_unregister();
rval = 0;
}
return rval;
}
static int skygw_log_disable(logfile_id_t id)
{
bool rval = -1;
if (logmanager_register(true))
{
CHK_LOGMANAGER(lm);
lm->lm_enabled_logfiles &= ~id;
/**
* Set global variable
*/
lm_enabled_logfiles_bitmask = lm->lm_enabled_logfiles;
logmanager_unregister();
rval = 0;
}
return rval;
}
/**
* Set log augmentation.
*
@ -2009,21 +1916,6 @@ static bool logfile_init(logfile_t* logfile,
goto return_with_succ;
}
#if defined(SS_DEBUG)
if (store_shmem && !log_config.use_stdout)
{
fprintf(stderr, "%s\t: %s->%s\n",
STRLOGNAME(LOGFILE_ERROR),
logfile->lf_full_link_name,
logfile->lf_full_file_name);
}
else if (!log_config.use_stdout)
{
fprintf(stderr, "%s\t: %s\n",
STRLOGNAME(LOGFILE_ERROR),
logfile->lf_full_file_name);
}
#endif
succ = true;
logfile->lf_state = RUN;
CHK_LOGFILE(logfile);
@ -2258,17 +2150,16 @@ static bool thr_flush_file(logmanager_t *lm, filewriter_t *fwr)
(flush_logfile || do_flushall));
if (err)
{
// TODO: Log this to syslog.
char errbuf[STRERROR_BUFLEN];
fprintf(stderr,
"Error : Write to %s log "
": %s failed due to %d, "
"%s. Disabling the log.",
STRLOGNAME(LOGFILE_ERROR),
"Error : Writing to the log-file %s failed due to (%d, %s). "
"Disabling writing to the log.",
lf->lf_full_file_name,
err,
strerror_r(err, errbuf, sizeof(errbuf)));
/** Force log off */
skygw_log_disable(LOGFILE_ERROR);
mxs_log_set_maxscalelog_enabled(false);
}
/**
* Reset buffer's counters and mark
@ -2661,26 +2552,6 @@ int mxs_log_rotate()
return err;
}
static logfile_id_t priority_to_file_id(int priority)
{
switch (priority)
{
case LOG_DEBUG:
return LOGFILE_DEBUG;
case LOG_INFO:
return LOGFILE_TRACE;
case LOG_NOTICE:
return LOGFILE_MESSAGE;
case LOG_ERR:
case LOG_WARNING:
case LOG_CRIT:
case LOG_ALERT:
case LOG_EMERG:
default:
return LOGFILE_ERROR;
}
}
static const char* priority_name(int priority)
{
switch (priority)
@ -2722,19 +2593,16 @@ int mxs_log_set_priority_enabled(int priority, bool enable)
if ((priority & ~LOG_PRIMASK) == 0)
{
logfile_id_t id = priority_to_file_id(priority);
int bit = (1 << priority);
if (enable)
{
// TODO: Put behind spinlock.
lm_enabled_priorities_bitmask |= bit;
skygw_log_enable(id);
}
else
{
lm_enabled_priorities_bitmask &= ~bit;
skygw_log_disable(id);
}
MXS_NOTICE("The logging of %s messages has been %sd.", priority_name(priority), text);
@ -2762,35 +2630,6 @@ static const char PREFIX_NOTICE[] = "notice : ";
static const char PREFIX_INFO[] = "info : ";
static const char PREFIX_DEBUG[] = "debug : ";
static logfile_id_t priority_to_id(int priority)
{
assert((priority & ~LOG_PRIMASK) == 0);
switch (priority)
{
case LOG_EMERG:
case LOG_ALERT:
case LOG_CRIT:
case LOG_ERR:
case LOG_WARNING:
return LOGFILE_ERROR;
case LOG_NOTICE:
return LOGFILE_MESSAGE;
case LOG_INFO:
return LOGFILE_TRACE;
case LOG_DEBUG:
return LOGFILE_DEBUG;
default:
// Can't happen!
assert(!true);
return LOGFILE_ERROR;
}
}
static log_prefix_t priority_to_prefix(int priority)
{
assert((priority & ~LOG_PRIMASK) == 0);
@ -2893,9 +2732,7 @@ int mxs_log_message(int priority,
if ((priority & ~LOG_PRIMASK) == 0) // Check that the priority is ok,
{
logfile_id_t id = priority_to_id(priority);
if (LOG_IS_ENABLED(id))
if (MXS_LOG_PRIORITY_IS_ENABLED(priority))
{
va_list valist;
@ -2912,7 +2749,8 @@ int mxs_log_message(int priority,
static const char FORMAT_FUNCTION[] = "(%s): ";
int augmentation = log_config.augmentation; // Other thread might change log_config.augmentation.
// Other thread might change log_config.augmentation.
int augmentation = log_config.augmentation;
int augmentation_len = 0;
switch (augmentation)

View File

@ -46,16 +46,6 @@ enum mxs_log_priorities
MXS_LOG_WARNING | MXS_LOG_NOTICE | MXS_LOG_INFO | MXS_LOG_DEBUG),
};
typedef enum
{
LOGFILE_ERROR = 1,
LOGFILE_FIRST = LOGFILE_ERROR,
LOGFILE_MESSAGE = 2,
LOGFILE_TRACE = 4,
LOGFILE_DEBUG = 8,
LOGFILE_LAST = LOGFILE_DEBUG
} logfile_id_t;
typedef enum
{
LOG_TARGET_DEFAULT = 0,
@ -69,16 +59,10 @@ typedef enum
typedef struct log_info
{
size_t li_sesid;
int li_enabled_logs;
int li_enabled_priorities;
} log_info_t;
#define LE LOGFILE_ERROR
#define LM LOGFILE_MESSAGE
#define LT LOGFILE_TRACE
#define LD LOGFILE_DEBUG
extern int lm_enabled_priorities_bitmask;
extern int lm_enabled_logfiles_bitmask;
extern ssize_t log_ses_count[];
extern __thread log_info_t tls_log_info;
@ -86,12 +70,10 @@ extern __thread log_info_t tls_log_info;
* Check if specified log type is enabled in general or if it is enabled
* for the current session.
*/
#define LOG_IS_ENABLED(id) (((lm_enabled_logfiles_bitmask & id) || \
(log_ses_count[id] > 0 && \
tls_log_info.li_enabled_logs & id)) ? true : false)
// TODO: Add this at a later stage.
#define MXS_LOG_PRIORITY_IS_ENABLED(priority) false
#define MXS_LOG_PRIORITY_IS_ENABLED(priority) \
(((lm_enabled_priorities_bitmask & (1 << priority)) || \
(log_ses_count[priority] > 0 && \
tls_log_info.li_enabled_priorities & (1 << priority))) ? true : false)
/**
* LOG_AUGMENT_WITH_FUNCTION Each logged line is suffixed with [function-name].

View File

@ -62,36 +62,14 @@ const int N_THR = 4;
#define TEST_ERROR(msg)\
do { fprintf(stderr, "[%s:%d]: %s\n", basename(__FILE__), __LINE__, msg); } while (false)
static logfile_id_t id_to_priority(logfile_id_t id)
static void skygw_log_enable(int priority)
{
switch (id)
{
case LOGFILE_ERROR:
return LOG_ERR;
case LOGFILE_MESSAGE:
return LOG_NOTICE;
case LOGFILE_TRACE:
return LOG_INFO;
case LOGFILE_DEBUG:
return LOG_DEBUG;
default:
assert(!true);
return LOG_ERR;
}
mxs_log_set_priority_enabled(priority, true);
}
static void skygw_log_enable(logfile_id_t id)
static void skygw_log_disable(int priority)
{
mxs_log_set_priority_enabled(id_to_priority(id), true);
}
static void skygw_log_disable(logfile_id_t id)
{
mxs_log_set_priority_enabled(id_to_priority(id), false);
mxs_log_set_priority_enabled(priority, false);
}
int main(int argc, char* argv[])
@ -187,33 +165,33 @@ int main(int argc, char* argv[])
logstr = "My name is %s %d years and %d months.";
#if !defined(SS_DEBUG)
skygw_log_enable(LOGFILE_TRACE);
skygw_log_enable(LOG_INFO);
#endif
err = MXS_INFO(logstr, "TraceyTracey", 3, 7);
mxs_log_flush();
#if !defined(SS_DEBUG)
skygw_log_enable(LOGFILE_TRACE);
skygw_log_enable(LOG_INFO);
#endif
logstr = "My name is Tracey Tracey 47 years and 7 months.";
err = MXS_INFO("%s", logstr);
#if !defined(SS_DEBUG)
skygw_log_enable(LOGFILE_TRACE);
skygw_log_enable(LOG_INFO);
#endif
logstr = "My name is Stacey %s";
err = MXS_INFO(logstr, " ");
mxs_log_finish();
#if !defined(SS_DEBUG)
skygw_log_enable(LOGFILE_TRACE);
skygw_log_enable(LOG_INFO);
#endif
logstr = "My name is Philip";
err = MXS_INFO("%s", logstr);
#if !defined(SS_DEBUG)
skygw_log_enable(LOGFILE_TRACE);
skygw_log_enable(LOG_INFO);
#endif
logstr = "Philip.";
err = MXS_INFO("%s", logstr);
#if !defined(SS_DEBUG)
skygw_log_enable(LOGFILE_TRACE);
skygw_log_enable(LOG_INFO);
#endif
logstr = "Ph%dlip.";
err = MXS_INFO(logstr, 1);
@ -362,7 +340,7 @@ int main(int argc, char* argv[])
* Test enable/disable log.
*/
#if !defined(SS_DEBUG)
skygw_log_enable(LOGFILE_TRACE);
skygw_log_enable(LOG_INFO);
#endif
succp = mxs_log_init(NULL, "/tmp", LOG_TARGET_FS);
ss_dassert(succp);
@ -371,7 +349,7 @@ int main(int argc, char* argv[])
err = MXS_ERROR("%s", logstr);
ss_dassert(err == 0);
skygw_log_disable(LOGFILE_TRACE);
skygw_log_disable(LOG_INFO);
logstr = ("1.\tWrite once to ERROR and twice to MESSAGE log.");
err = MXS_NOTICE("%s", logstr);
@ -381,7 +359,7 @@ int main(int argc, char* argv[])
err = MXS_ERROR("%s", logstr);
ss_dassert(err == 0);
skygw_log_enable(LOGFILE_TRACE);
skygw_log_enable(LOG_INFO);
logstr = ("2.\tWrite to once to ERROR, twice to MESSAGE and "
"three times to TRACE log.");
@ -392,7 +370,7 @@ int main(int argc, char* argv[])
err = MXS_ERROR("%s", logstr);
ss_dassert(err == 0);
skygw_log_disable(LOGFILE_ERROR);
skygw_log_disable(LOG_ERR);
logstr = ("3.\tWrite to once to MESSAGE and twice to TRACE log.");
err = MXS_NOTICE("%s", logstr);
@ -402,8 +380,8 @@ int main(int argc, char* argv[])
err = MXS_ERROR("%s", logstr);
ss_dassert(err == 0);
skygw_log_disable(LOGFILE_MESSAGE);
skygw_log_disable(LOGFILE_TRACE);
skygw_log_disable(LOG_NOTICE);
skygw_log_disable(LOG_INFO);
logstr = ("4.\tWrite to none.");
err = MXS_NOTICE("%s", logstr);
@ -413,8 +391,8 @@ int main(int argc, char* argv[])
err = MXS_ERROR("%s", logstr);
ss_dassert(err == 0);
skygw_log_enable(LOGFILE_ERROR);
skygw_log_enable(LOGFILE_MESSAGE);
skygw_log_enable(LOG_ERR);
skygw_log_enable(LOG_NOTICE);
logstr = ("4.\tWrite once to ERROR and twice to MESSAGE log.");
err = MXS_NOTICE("%s", logstr);
@ -432,7 +410,7 @@ int main(int argc, char* argv[])
succp = mxs_log_init(NULL, "/tmp", LOG_TARGET_FS);
ss_dassert(succp);
#if !defined(SS_DEBUG)
skygw_log_enable(LOGFILE_TRACE);
skygw_log_enable(LOG_INFO);
#endif
logstr = ("\tTEST 4 - test spreading logs down to other logs.");
err = MXS_ERROR("%s", logstr);
@ -446,12 +424,12 @@ int main(int argc, char* argv[])
err = MXS_NOTICE("%s", logstr);
ss_dassert(err == 0);
skygw_log_enable(LOGFILE_TRACE);
skygw_log_enable(LOG_INFO);
logstr = ("3.\tWrite to TRACE log only.");
err = MXS_INFO("%s", logstr);
ss_dassert(err == 0);
skygw_log_disable(LOGFILE_MESSAGE);
skygw_log_disable(LOG_NOTICE);
logstr = ("4.\tWrite to ERROR and thus also to TRACE log. "
"MESSAGE is disabled.");
@ -468,7 +446,7 @@ int main(int argc, char* argv[])
succp = mxs_log_init(NULL, "/tmp", LOG_TARGET_FS);
ss_dassert(succp);
#if !defined(SS_DEBUG)
skygw_log_enable(LOGFILE_TRACE);
skygw_log_enable(LOG_INFO);
#endif
logstr = ("6.\tWrite to ERROR and thus also to MESSAGE and TRACE logs.");
err = MXS_ERROR("%s", logstr);
@ -479,11 +457,11 @@ int main(int argc, char* argv[])
ss_dassert(err == 0);
logstr = ("8.\tWrite to TRACE log only.");
skygw_log_enable(LOGFILE_TRACE);
skygw_log_enable(LOG_INFO);
err = MXS_INFO("%s", logstr);
ss_dassert(err == 0);
skygw_log_disable(LOGFILE_MESSAGE);
skygw_log_disable(LOG_NOTICE);
logstr = ("9.\tWrite to ERROR and thus also to TRACE log. "
"MESSAGE is disabled");
@ -495,7 +473,7 @@ int main(int argc, char* argv[])
err = MXS_NOTICE("%s", logstr);
ss_dassert(err == 0);
skygw_log_enable(LOGFILE_MESSAGE);
skygw_log_enable(LOG_NOTICE);
err = MXS_ERROR("11.\tWrite to all logs some formattings : "
"%d %s %d",
@ -572,7 +550,7 @@ static void* thr_run(void* data)
logstr = ("For automatic and register variables, it is done each time the function or block is entered.");
#if !defined(SS_DEBUG)
skygw_log_enable(LOGFILE_TRACE);
skygw_log_enable(LOG_INFO);
#endif
err = MXS_INFO("%s", logstr);
if (err != 0)
@ -609,7 +587,7 @@ static void* thr_run(void* data)
mxs_log_init(NULL, "/tmp", LOG_TARGET_FS);
logstr = ("For automatic and register variables, it is done each time the function or block is entered.");
#if !defined(SS_DEBUG)
skygw_log_enable(LOGFILE_TRACE);
skygw_log_enable(LOG_INFO);
#endif
err = MXS_INFO("%s", logstr);
if (err != 0)
@ -640,12 +618,12 @@ static void* thr_run(void* data)
mxs_log_finish();
mxs_log_init(NULL, "/tmp", LOG_TARGET_FS);
#if !defined(SS_DEBUG)
skygw_log_enable(LOGFILE_TRACE);
skygw_log_enable(LOG_INFO);
#endif
mxs_log_flush();
logstr = ("For automatic and register variables, it is done each time the function or block is entered.");
#if !defined(SS_DEBUG)
skygw_log_enable(LOGFILE_TRACE);
skygw_log_enable(LOG_INFO);
#endif
err = MXS_INFO("%s", logstr);
if (err != 0)

View File

@ -23,36 +23,14 @@
#include <skygw_utils.h>
#include <log_manager.h>
static logfile_id_t id_to_priority(logfile_id_t id)
static void skygw_log_enable(int priority)
{
switch (id)
{
case LOGFILE_ERROR:
return LOG_ERR;
case LOGFILE_MESSAGE:
return LOG_NOTICE;
case LOGFILE_TRACE:
return LOG_INFO;
case LOGFILE_DEBUG:
return LOG_DEBUG;
default:
assert(!true);
return LOG_ERR;
}
mxs_log_set_priority_enabled(priority, true);
}
static void skygw_log_enable(logfile_id_t id)
static void skygw_log_disable(int priority)
{
mxs_log_set_priority_enabled(id_to_priority(id), true);
}
static void skygw_log_disable(logfile_id_t id)
{
mxs_log_set_priority_enabled(id_to_priority(id), false);
mxs_log_set_priority_enabled(priority, false);
}
int main(int argc, char** argv)
@ -107,9 +85,9 @@ int main(int argc, char** argv)
}
ss_dassert(succp);
skygw_log_disable(LOGFILE_TRACE);
skygw_log_disable(LOGFILE_MESSAGE);
skygw_log_disable(LOGFILE_DEBUG);
skygw_log_disable(LOG_INFO);
skygw_log_disable(LOG_NOTICE);
skygw_log_disable(LOG_DEBUG);
for (i = 0; i < iterations; i++)
{

View File

@ -423,7 +423,7 @@ static skygw_query_type_t resolve_query_type(
lex,
&set_autocommit_stmt))
{
if (LOG_IS_ENABLED(LOGFILE_TRACE))
if (MXS_LOG_PRIORITY_IS_ENABLED(LOG_INFO))
{
if (sql_command_flags[lex->sql_command] &
CF_IMPLICT_COMMIT_BEGIN)
@ -446,7 +446,7 @@ static skygw_query_type_t resolve_query_type(
if (set_autocommit_stmt == 0)
{
if (LOG_IS_ENABLED(LOGFILE_TRACE))
if (MXS_LOG_PRIORITY_IS_ENABLED(LOG_INFO))
{
MXS_INFO("Disable autocommit : implicit START TRANSACTION"
" before executing the next command.");

View File

@ -127,23 +127,23 @@ size_t dcb_get_session_id(
* Read log info from session through DCB and store values to memory locations
* passed as parameters.
*
* @param dcb DCB
* @param sesid location where session id is to be copied
* @param enabled_logs bit field indicating which log types are enabled for the
* @param dcb DCB
* @param sesid location where session id is to be copied
* @param enabled_log_prioritiess bit field indicating which log types are enabled for the
* session
*
*@return true if call arguments included memory addresses, false if any of the
*parameters was NULL.
*/
*@return true if call arguments included memory addresses, false if any of the
* parameters was NULL.
*/
bool dcb_get_ses_log_info(
DCB *dcb,
size_t *sesid,
int *enabled_logs)
int *enabled_log_priorities)
{
if (sesid && enabled_logs && dcb && dcb->session)
if (sesid && enabled_log_priorities && dcb && dcb->session)
{
*sesid = dcb->session->ses_id;
*enabled_logs = dcb->session->ses_enabled_logs;
*enabled_log_priorities = dcb->session->enabled_log_priorities;
return true;
}
return false;
@ -620,7 +620,7 @@ dcb_process_victim_queue(DCB *listofdcb)
dcb_get_ses_log_info(dcb,
&tls_log_info.li_sesid,
&tls_log_info.li_enabled_logs);
&tls_log_info.li_enabled_priorities);
dcb->state = DCB_STATE_DISCONNECTED;
nextdcb = dcb->memdata.next;
@ -1247,7 +1247,7 @@ dcb_write_when_already_queued(DCB *dcb, GWBUF *queue)
static void
dcb_log_write_failure(DCB *dcb, GWBUF *queue, int eno)
{
if (LOG_IS_ENABLED(LOGFILE_DEBUG))
if (MXS_LOG_PRIORITY_IS_ENABLED(LOG_DEBUG))
{
if (eno == EPIPE)
{
@ -1264,7 +1264,7 @@ dcb_log_write_failure(DCB *dcb, GWBUF *queue, int eno)
}
}
if (LOG_IS_ENABLED(LOGFILE_ERROR))
if (MXS_LOG_PRIORITY_IS_ENABLED(LOG_ERR))
{
if (eno != EPIPE &&
eno != EAGAIN &&
@ -1430,7 +1430,7 @@ dcb_write_SSL_error_report (DCB *dcb, int ret, int ssl_errno)
{
char errbuf[STRERROR_BUFLEN];
if (LOG_IS_ENABLED(LOGFILE_DEBUG))
if (MXS_LOG_PRIORITY_IS_ENABLED(LOG_DEBUG))
{
switch(ssl_errno)
{
@ -1464,7 +1464,7 @@ dcb_write_SSL_error_report (DCB *dcb, int ret, int ssl_errno)
}
}
if (LOG_IS_ENABLED(LOGFILE_ERROR) && ssl_errno != SSL_ERROR_WANT_WRITE)
if (MXS_LOG_PRIORITY_IS_ENABLED(LOG_ERR) && ssl_errno != SSL_ERROR_WANT_WRITE)
{
if (ret == -1)
{

View File

@ -860,7 +860,7 @@ unsigned long qtime;
/** Read session id to thread's local storage */
dcb_get_ses_log_info(dcb,
&tls_log_info.li_sesid,
&tls_log_info.li_enabled_logs);
&tls_log_info.li_enabled_priorities);
if (poll_dcb_session_check(dcb, "write_ready"))
{
@ -890,7 +890,7 @@ unsigned long qtime;
&pollStats.n_accept, 1);
dcb_get_ses_log_info(dcb,
&tls_log_info.li_sesid,
&tls_log_info.li_enabled_logs);
&tls_log_info.li_enabled_priorities);
if (poll_dcb_session_check(dcb, "accept"))
{
@ -908,7 +908,7 @@ unsigned long qtime;
/** Read session id to thread's local storage */
dcb_get_ses_log_info(dcb,
&tls_log_info.li_sesid,
&tls_log_info.li_enabled_logs);
&tls_log_info.li_enabled_priorities);
if (poll_dcb_session_check(dcb, "read"))
{
@ -944,7 +944,7 @@ unsigned long qtime;
/** Read session id to thread's local storage */
dcb_get_ses_log_info(dcb,
&tls_log_info.li_sesid,
&tls_log_info.li_enabled_logs);
&tls_log_info.li_enabled_priorities);
if (poll_dcb_session_check(dcb, "error"))
{
@ -974,7 +974,7 @@ unsigned long qtime;
/** Read session id to thread's local storage */
dcb_get_ses_log_info(dcb,
&tls_log_info.li_sesid,
&tls_log_info.li_enabled_logs);
&tls_log_info.li_enabled_priorities);
if (poll_dcb_session_check(dcb, "hangup EPOLLHUP"))
{
@ -1008,7 +1008,7 @@ unsigned long qtime;
/** Read session id to thread's local storage */
dcb_get_ses_log_info(dcb,
&tls_log_info.li_sesid,
&tls_log_info.li_enabled_logs);
&tls_log_info.li_enabled_priorities);
if (poll_dcb_session_check(dcb, "hangup EPOLLRDHUP"))
{

View File

@ -261,38 +261,34 @@ session_set_dummy(DCB *client_dcb)
}
/**
* Enable specified logging for the current session and increase logger
* Enable specified log priority for the current session and increase logger
* counter.
* Generic logging setting has precedence over session-specific setting.
*
* @param ses session
* @param id logfile identifier
*
* @param ses session
* @param priority syslog priority
*/
void session_enable_log(
SESSION* ses,
logfile_id_t id)
void session_enable_log_priority(SESSION* ses, int priority)
{
ses->ses_enabled_logs |= id;
atomic_add((int *)&log_ses_count[id], 1);
ses->enabled_log_priorities |= (1 << priority);
atomic_add((int *)&log_ses_count[priority], 1);
}
/**
* Disable specified logging for the current session and decrease logger
* Disable specified log priority for the current session and decrease logger
* counter.
* Generic logging setting has precedence over session-specific setting.
*
*
* @param ses session
* @param id logfile identifier
* @param priority syslog priority
*/
void session_disable_log(
SESSION* ses,
logfile_id_t id)
void session_disable_log_priority(SESSION* ses, int priority)
{
if (ses->ses_enabled_logs & id)
{
ses->ses_enabled_logs &= ~id;
atomic_add((int *)&log_ses_count[id], -1);
}
if (ses->enabled_log_priorities & (1 << priority))
{
ses->enabled_log_priorities &= ~(1 << priority);
atomic_add((int *)&log_ses_count[priority], -1);
}
}
/**
@ -473,7 +469,7 @@ session_free(SESSION *session)
session->ses_id);
/** Disable trace and decrease trace logger counter */
session_disable_log(session, LT);
session_disable_log_priority(session, LOG_INFO);
/** If session doesn't have parent referencing to it, it can be freed */
if (!session->ses_is_child)

View File

@ -124,7 +124,7 @@ typedef struct session {
SPINLOCK ses_lock;
session_state_t state; /*< Current descriptor state */
size_t ses_id; /*< Unique session identifier */
int ses_enabled_logs; /*< Bitfield of enabled logs */
int enabled_log_priorities; /*< Bitfield of enabled syslog priorities */
struct dcb *client; /*< The client connection */
void *data; /*< The session data */
void *router_session; /*< The router instance data */
@ -178,8 +178,8 @@ char *session_state(int);
bool session_link_dcb(SESSION *, struct dcb *);
int session_unlink_dcb(SESSION*, DCB*);
SESSION* get_session_by_router_ses(void* rses);
void session_enable_log(SESSION* ses, logfile_id_t id);
void session_disable_log(SESSION* ses, logfile_id_t id);
void session_enable_log_priority(SESSION* ses, int priority);
void session_disable_log_priority(SESSION* ses, int priority);
void session_close_timeouts(void* data);
RESULTSET *sessionGetList(SESSIONLISTFILTER);

View File

@ -487,7 +487,7 @@ static int gw_mysql_do_authentication(DCB *dcb, GWBUF **buf) {
return MYSQL_FAILED_AUTH_SSL;
}
if(LOG_IS_ENABLED(LT) && ssl)
if (MXS_LOG_PRIORITY_IS_ENABLED(LOG_INFO) && ssl)
{
MXS_INFO("User %s@%s connected to service '%s' with SSL.",
protocol->owner_dcb->user,

View File

@ -419,6 +419,8 @@ static void enable_log_priority(DCB *, char *);
static void disable_log_priority(DCB *, char *);
static void enable_sess_log_action(DCB *dcb, char *arg1, char *arg2);
static void disable_sess_log_action(DCB *dcb, char *arg1, char *arg2);
static void enable_sess_log_priority(DCB *dcb, char *arg1, char *arg2);
static void disable_sess_log_priority(DCB *dcb, char *arg1, char *arg2);
static void enable_monitor_replication_heartbeat(DCB *dcb, MONITOR *monitor);
static void disable_monitor_replication_heartbeat(DCB *dcb, MONITOR *monitor);
static void enable_service_root(DCB *dcb, SERVICE *service);
@ -462,12 +464,24 @@ struct subcommand enableoptions[] = {
"sessionlog",
2,
enable_sess_log_action,
"Enable Log options for a single session. Usage: enable sessionlog [trace | error | "
"[deprecated] Enable Log options for a single session. Usage: enable sessionlog [trace | error | "
"message | debug] <session id>\t E.g. enable sessionlog message 123.",
"Enable Log options for a single session. Usage: enable sessionlog [trace | error | "
"[deprecated] Enable Log options for a single session. Usage: enable sessionlog [trace | error | "
"message | debug] <session id>\t E.g. enable sessionlog message 123.",
{ARG_TYPE_STRING, ARG_TYPE_STRING, 0}
},
{
"sessionlog-priority",
2,
enable_sess_log_priority,
"Enable a logging priority for a particular. "
"Usage: enable sessionlog-priority [err | warning | notice | info | debug] <session id>"
"message | debug] <session id>\t E.g. enable sessionlog-priority info 123.",
"Enable a logging priority for a particular. "
"Usage: enable sessionlog-priority [err | warning | notice | info | debug] <session id>"
"message | debug] <session id>\t E.g. enable sessionlog-priority info 123.",
{ARG_TYPE_STRING, ARG_TYPE_STRING, 0}
},
{
"root",
1,
@ -532,12 +546,24 @@ struct subcommand disableoptions[] = {
"sessionlog",
2,
disable_sess_log_action,
"Disable Log options for a single session. Usage: disable sessionlog [trace | error | "
"[deprecated] Disable Log options for a single session. Usage: disable sessionlog [trace | error | "
"message | debug] <session id>\t E.g. disable sessionlog message 123.",
"Disable Log options for a single session. Usage: disable sessionlog [trace | error | "
"[deprecated] Disable Log options for a single session. Usage: disable sessionlog [trace | error | "
"message | debug] <session id>\t E.g. disable sessionlog message 123.",
{ARG_TYPE_STRING, ARG_TYPE_STRING, 0}
},
{
"sessionlog-priority",
2,
disable_sess_log_priority,
"Disable a logging priority for a particular session. "
"Usage: disable sessionlog-priority [err | warning | notice | info | debug] <session id>"
"message | debug] <session id>\t E.g. enable sessionlog-priority info 123.",
"Enable a logging priority for a particular session. "
"Usage: disable sessionlog-priority [err | warning | notice | info | debug] <session id>"
"message | debug] <session id>\t E.g. enable sessionlog-priority info 123.",
{ARG_TYPE_STRING, ARG_TYPE_STRING, 0}
},
{
"root",
1,
@ -1374,110 +1400,6 @@ disable_service_root(DCB *dcb, SERVICE *service)
serviceEnableRootUser(service, 0);
}
/**
* Enables a log for a single session
* @param session The session in question
* @param dcb Client DCB
* @param type Which log to enable
*/
static void enable_sess_log_action(DCB *dcb, char *arg1, char *arg2)
{
logfile_id_t type;
size_t id = 0;
int max_len = strlen("message");
SESSION* session = get_all_sessions();
ss_dassert(arg1 != NULL && arg2 != NULL && session != NULL);
if (strncmp(arg1, "debug", max_len) == 0)
{
type = LOGFILE_DEBUG;
}
else if (strncmp(arg1, "trace", max_len) == 0)
{
type = LOGFILE_TRACE;
}
else if (strncmp(arg1, "error", max_len) == 0)
{
type = LOGFILE_ERROR;
}
else if (strncmp(arg1, "message", max_len) == 0)
{
type = LOGFILE_MESSAGE;
}
else
{
dcb_printf(dcb, "%s is not supported for enable log\n", arg1);
return ;
}
id = (size_t)strtol(arg2, 0, 0);
while(session)
{
if (session->ses_id == id)
{
session_enable_log(session, type);
return;
}
session = session->next;
}
dcb_printf(dcb, "Session not found: %s\n", arg2);
}
/**
* Disables a log for a single session
* @param session The session in question
* @param dcb Client DCB
* @param type Which log to disable
*/
static void disable_sess_log_action(DCB *dcb, char *arg1, char *arg2)
{
logfile_id_t type;
int id = 0;
int max_len = strlen("message");
SESSION* session = get_all_sessions();
ss_dassert(arg1 != NULL && arg2 != NULL && session != NULL);
if (strncmp(arg1, "debug", max_len) == 0)
{
type = LOGFILE_DEBUG;
}
else if (strncmp(arg1, "trace", max_len) == 0)
{
type = LOGFILE_TRACE;
}
else if (strncmp(arg1, "error", max_len) == 0)
{
type = LOGFILE_ERROR;
}
else if (strncmp(arg1, "message", max_len) == 0)
{
type = LOGFILE_MESSAGE;
}
else
{
dcb_printf(dcb, "%s is not supported for disable log\n", arg1);
return ;
}
id = (size_t)strtol(arg2, 0, 0);
while(session)
{
if (session->ses_id == id)
{
session_disable_log(session, type);
return;
}
session = session->next;
}
dcb_printf(dcb, "Session not found: %s\n", arg2);
}
struct log_action_entry
{
const char* name;
@ -1513,6 +1435,196 @@ static bool get_log_action(const char* name, struct log_action_entry* entryp)
return found;
}
/**
* Enables a log for a single session
* @param session The session in question
* @param dcb Client DCB
* @param type Which log to enable
*/
static void enable_sess_log_action(DCB *dcb, char *arg1, char *arg2)
{
struct log_action_entry entry;
if (get_log_action(arg1, &entry))
{
size_t id = (size_t) strtol(arg2, 0, 0);
// TODO: This is totally non thread-safe.
SESSION* session = get_all_sessions();
while (session)
{
if (session->ses_id == id)
{
session_enable_log_priority(session, entry.priority);
break;
}
session = session->next;
}
if (!session)
{
dcb_printf(dcb, "Session not found: %s\n", arg2);
}
}
else
{
dcb_printf(dcb, "%s is not supported for enable log\n", arg1);
}
}
/**
* Disables a log for a single session
* @param session The session in question
* @param dcb Client DCB
* @param type Which log to disable
*/
static void disable_sess_log_action(DCB *dcb, char *arg1, char *arg2)
{
struct log_action_entry entry;
if (get_log_action(arg1, &entry))
{
size_t id = (size_t) strtol(arg2, 0, 0);
// TODO: This is totally non thread-safe.
SESSION* session = get_all_sessions();
while (session)
{
if (session->ses_id == id)
{
session_disable_log_priority(session, entry.priority);
break;
}
session = session->next;
}
if (!session)
{
dcb_printf(dcb, "Session not found: %s\n", arg2);
}
}
else
{
dcb_printf(dcb, "%s is not supported for disable log\n", arg1);
}
}
struct log_priority_entry
{
const char* name;
int priority;
};
static int compare_log_priority_entries(const void* l, const void* r)
{
const struct log_priority_entry* l_entry = (const struct log_priority_entry*) l;
const struct log_priority_entry* r_entry = (const struct log_priority_entry*) r;
return strcmp(l_entry->name, r_entry->name);
}
static int string_to_priority(const char* name)
{
static const struct log_priority_entry LOG_PRIORITY_ENTRIES[] =
{
// NOTE: If you make changes to this array, ensure that it remains alphabetically ordered.
{ "debug", LOG_DEBUG },
{ "err", LOG_ERR },
{ "info", LOG_INFO },
{ "notice", LOG_NOTICE },
{ "warning", LOG_WARNING },
};
const size_t N_LOG_PRIORITY_ENTRIES = sizeof(LOG_PRIORITY_ENTRIES) / sizeof(LOG_PRIORITY_ENTRIES[0]);
struct log_priority_entry key = { name, -1 };
struct log_priority_entry* result = bsearch(&key,
LOG_PRIORITY_ENTRIES,
N_LOG_PRIORITY_ENTRIES,
sizeof(struct log_priority_entry),
compare_log_priority_entries);
return result ? result->priority : -1;
}
/**
* Enables a log priority for a single session
* @param session The session in question
* @param dcb Client DCB
* @param type Which log to enable
*/
static void enable_sess_log_priority(DCB *dcb, char *arg1, char *arg2)
{
int priority = string_to_priority(arg1);
if (priority != -1)
{
size_t id = (size_t) strtol(arg2, 0, 0);
// TODO: This is totally non thread-safe.
SESSION* session = get_all_sessions();
while (session)
{
if (session->ses_id == id)
{
session_enable_log_priority(session, priority);
break;
}
session = session->next;
}
if (!session)
{
dcb_printf(dcb, "Session not found: %s\n", arg2);
}
}
else
{
dcb_printf(dcb, "'%s' is not a supported log priority\n", arg1);
}
}
/**
* Disable a log priority for a single session
* @param session The session in question
* @param dcb Client DCB
* @param type Which log to enable
*/
static void disable_sess_log_priority(DCB *dcb, char *arg1, char *arg2)
{
int priority = string_to_priority(arg1);
if (priority != -1)
{
size_t id = (size_t) strtol(arg2, 0, 0);
// TODO: This is totally non thread-safe.
SESSION* session = get_all_sessions();
while (session)
{
if (session->ses_id == id)
{
session_disable_log_priority(session, priority);
break;
}
session = session->next;
}
if (!session)
{
dcb_printf(dcb, "Session not found: %s\n", arg2);
}
}
else
{
dcb_printf(dcb, "'%s' is not a supported log priority\n", arg1);
}
}
/**
* The log enable action
*/
@ -1555,44 +1667,6 @@ static void disable_log_action(DCB *dcb, char *arg1)
}
}
struct log_priority_entry
{
const char* name;
int priority;
};
static int compare_log_priority_entries(const void* l, const void* r)
{
const struct log_priority_entry* l_entry = (const struct log_priority_entry*) l;
const struct log_priority_entry* r_entry = (const struct log_priority_entry*) r;
return strcmp(l_entry->name, r_entry->name);
}
static int string_to_priority(const char* name)
{
static const struct log_priority_entry LOG_PRIORITY_ENTRIES[] =
{
// NOTE: If you make changes to this array, ensure that it remains alphabetically ordered.
{ "debug", LOG_DEBUG },
{ "err", LOG_ERR },
{ "info", LOG_INFO },
{ "notice", LOG_NOTICE },
{ "warning", LOG_WARNING },
};
const size_t N_LOG_PRIORITY_ENTRIES = sizeof(LOG_PRIORITY_ENTRIES) / sizeof(LOG_PRIORITY_ENTRIES[0]);
struct log_priority_entry key = { name, -1 };
struct log_priority_entry* result = bsearch(&key,
LOG_PRIORITY_ENTRIES,
N_LOG_PRIORITY_ENTRIES,
sizeof(struct log_priority_entry),
compare_log_priority_entries);
return result ? result->priority : -1;
}
/**
* The log-priority enable action
*/

View File

@ -2810,7 +2810,7 @@ static void clientReply (
*/
if (sescmd_cursor_is_active(scur))
{
if (LOG_IS_ENABLED(LOGFILE_ERROR) &&
if (MXS_LOG_PRIORITY_IS_ENABLED(LOG_ERR) &&
MYSQL_IS_ERROR_PACKET(((uint8_t *)GWBUF_DATA(writebuf))))
{
uint8_t* buf =
@ -3483,7 +3483,7 @@ static bool select_connect_backend_servers(
slaves_found);
}
if (LOG_IS_ENABLED(LT))
if (MXS_LOG_PRIORITY_IS_ENABLED(LOG_INFO))
{
for (i=0; i<router_nservers; i++)
{

View File

@ -2087,7 +2087,7 @@ static int routeQuery(
} /**< switch by packet type */
if (LOG_IS_ENABLED(LOGFILE_TRACE))
if (MXS_LOG_PRIORITY_IS_ENABLED(LOG_INFO))
{
uint8_t* packet = GWBUF_DATA(querybuf);
unsigned char ptype = packet[4];
@ -2713,7 +2713,7 @@ static void clientReply(ROUTER* instance,
*/
if (sescmd_cursor_is_active(scur))
{
if (LOG_IS_ENABLED(LOGFILE_ERROR) &&
if (MXS_LOG_PRIORITY_IS_ENABLED(LOG_ERR) &&
MYSQL_IS_ERROR_PACKET(((uint8_t *) GWBUF_DATA(writebuf))))
{
uint8_t* buf =
@ -3039,7 +3039,7 @@ static bool connect_backend_servers(
}
#endif
if (LOG_IS_ENABLED(LOGFILE_TRACE))
if (MXS_LOG_PRIORITY_IS_ENABLED(LOG_INFO))
{
MXS_INFO("Servers and connection counts:");
@ -3151,7 +3151,7 @@ static bool connect_backend_servers(
{
succp = true;
if (LOG_IS_ENABLED(LT))
if (MXS_LOG_PRIORITY_IS_ENABLED(LOG_INFO))
{
for (i=0; i<router_nservers; i++)
{
@ -3831,7 +3831,7 @@ static bool route_session_write(
{
DCB* dcb = backend_ref[i].bref_dcb;
if (LOG_IS_ENABLED(LOGFILE_TRACE))
if (MXS_LOG_PRIORITY_IS_ENABLED(LOG_INFO))
{
MXS_INFO("Route query to %s\t%s:%d%s",
(SERVER_IS_MASTER(backend_ref[i].bref_backend->backend_server) ?
@ -3939,7 +3939,7 @@ static bool route_session_write(
{
sescmd_cursor_t* scur;
if (LOG_IS_ENABLED(LOGFILE_TRACE))
if (MXS_LOG_PRIORITY_IS_ENABLED(LOG_INFO))
{
MXS_INFO("Route query to %s\t%s:%d%s",
(SERVER_IS_MASTER(backend_ref[i].bref_backend->backend_server) ?

View File

@ -2601,7 +2601,7 @@ route_session_write(
{
subsvc = router_cli_ses->subservice[i];
if(LOG_IS_ENABLED(LOGFILE_TRACE))
if (MXS_LOG_PRIORITY_IS_ENABLED(LOG_INFO))
{
MXS_INFO("Route query to %s%s%s",
i == 0 ? ">":"",
@ -2654,7 +2654,7 @@ route_session_write(
{
sescmd_cursor_t* scur;
if(LOG_IS_ENABLED(LOGFILE_TRACE))
if (MXS_LOG_PRIORITY_IS_ENABLED(LOG_INFO))
{
MXS_INFO("Route query to %s%s%s",
i == 0 ? ">":"",

View File

@ -167,17 +167,16 @@ typedef enum skygw_chk_t {
((t) == QUERY_TYPE_SHOW_TABLES ? "QUERY_TYPE_SHOW_TABLES" : \
"Unknown query type"))))))))))))))))))))))
#define STRLOGID(i) ((i) == LOGFILE_TRACE ? "LOGFILE_TRACE" : \
((i) == LOGFILE_MESSAGE ? "LOGFILE_MESSAGE" : \
((i) == LOGFILE_ERROR ? "LOGFILE_ERROR" : \
((i) == LOGFILE_DEBUG ? "LOGFILE_DEBUG" : \
"Unknown logfile type"))))
#define STRLOGNAME(n) ((n) == LOGFILE_TRACE ? "Trace log" : \
((n) == LOGFILE_MESSAGE ? "Message log" : \
((n) == LOGFILE_ERROR ? "Error log" : \
((n) == LOGFILE_DEBUG ? "Debug log" : \
"Unknown log file type"))))
#define STRLOGPRIORITYNAME(n)\
((n) == LOG_EMERG ? "LOG_EMERG" : \
((n) == LOG_ALERT ? "LOG_ALERT" : \
((n) == LOG_CRIT ? "LOG_CRIT" : \
((n) == LOG_ERR ? "LOG_ERR" : \
((n) == LOG_WARNING ? "LOG_WARNING" : \
((n) == LOG_NOTICE ? "LOG_NOTICE" : \
((n) == LOG_INFO ? "LOG_INFO" : \
((n) == LOG_DEBUG ? "LOG_DEBUG" : \
"Unknown log priority"))))))))
#define STRPACKETTYPE(p) ((p) == MYSQL_COM_INIT_DB ? "COM_INIT_DB" : \
((p) == MYSQL_COM_CREATE_DB ? "COM_CREATE_DB" : \