Log: Another step in the move from logfiles to priorities.
skygw_[enable|disable]_log has now been removed from the external interface and priorities must instead be set using mxs_log_set_priority_enabled(int priority, bool enabled). A bitmask is already being updated, but internally and as used by the LOG_IF macros, the actual enabling is still made using logfile ids. The configuration entries have been replaced as follows: log_messages -> log_notice log_trace -> log_info The old ones can be used, but cause a warning to be logged. Similarily the maxadmin commands have been updated. "[enable|disable] log ..." works as expected, but there will be a message about it being deprecated. Instead there is now a [enable|disable] log-priority err|warning|notice|info|debug command that should be used instead.
This commit is contained in:
@ -94,6 +94,12 @@ static struct
|
|||||||
*/
|
*/
|
||||||
int lm_enabled_logfiles_bitmask = 0;
|
int lm_enabled_logfiles_bitmask = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Variable holding the enabled priorities information.
|
||||||
|
* Used from logging macros.
|
||||||
|
*/
|
||||||
|
int lm_enabled_priorities_bitmask = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Thread-specific struct variable for storing current session id and currently
|
* Thread-specific struct variable for storing current session id and currently
|
||||||
* enabled log files for the session.
|
* enabled log files for the session.
|
||||||
@ -310,7 +316,6 @@ static char* blockbuf_get_writepos(blockbuf_t** p_bb,
|
|||||||
|
|
||||||
static void blockbuf_register(blockbuf_t* bb);
|
static void blockbuf_register(blockbuf_t* bb);
|
||||||
static void blockbuf_unregister(blockbuf_t* bb);
|
static void blockbuf_unregister(blockbuf_t* bb);
|
||||||
static bool logfile_set_enabled(logfile_id_t id, bool val);
|
|
||||||
static char* add_slash(char* str);
|
static char* add_slash(char* str);
|
||||||
|
|
||||||
static bool check_file_and_path(char* filename,
|
static bool check_file_and_path(char* filename,
|
||||||
@ -318,7 +323,6 @@ static bool check_file_and_path(char* filename,
|
|||||||
bool do_log);
|
bool do_log);
|
||||||
|
|
||||||
static bool file_is_symlink(char* filename);
|
static bool file_is_symlink(char* filename);
|
||||||
static int skygw_log_disable_raw(logfile_id_t id, bool emergency); /*< no locking */
|
|
||||||
static int find_last_seqno(strpart_t* parts, int seqno, int seqnoidx);
|
static int find_last_seqno(strpart_t* parts, int seqno, int seqnoidx);
|
||||||
void flushall_logfiles(bool flush);
|
void flushall_logfiles(bool flush);
|
||||||
bool thr_flushall_check();
|
bool thr_flushall_check();
|
||||||
@ -1150,7 +1154,7 @@ static blockbuf_t* blockbuf_init()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int skygw_log_enable(logfile_id_t id)
|
static int skygw_log_enable(logfile_id_t id)
|
||||||
{
|
{
|
||||||
bool rval = -1;
|
bool rval = -1;
|
||||||
|
|
||||||
@ -1158,14 +1162,11 @@ int skygw_log_enable(logfile_id_t id)
|
|||||||
{
|
{
|
||||||
CHK_LOGMANAGER(lm);
|
CHK_LOGMANAGER(lm);
|
||||||
|
|
||||||
if (logfile_set_enabled(id, true))
|
|
||||||
{
|
|
||||||
lm->lm_enabled_logfiles |= id;
|
lm->lm_enabled_logfiles |= id;
|
||||||
/**
|
/**
|
||||||
* Set global variable
|
* Set global variable
|
||||||
*/
|
*/
|
||||||
lm_enabled_logfiles_bitmask = lm->lm_enabled_logfiles;
|
lm_enabled_logfiles_bitmask = lm->lm_enabled_logfiles;
|
||||||
}
|
|
||||||
|
|
||||||
logmanager_unregister();
|
logmanager_unregister();
|
||||||
rval = 0;
|
rval = 0;
|
||||||
@ -1174,12 +1175,7 @@ int skygw_log_enable(logfile_id_t id)
|
|||||||
return rval;
|
return rval;
|
||||||
}
|
}
|
||||||
|
|
||||||
int skygw_log_disable(logfile_id_t id) /*< no locking */
|
static int skygw_log_disable(logfile_id_t id)
|
||||||
{
|
|
||||||
return skygw_log_disable_raw(id, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int skygw_log_disable_raw(logfile_id_t id, bool emergency) /*< no locking */
|
|
||||||
{
|
{
|
||||||
bool rval = -1;
|
bool rval = -1;
|
||||||
|
|
||||||
@ -1187,14 +1183,11 @@ static int skygw_log_disable_raw(logfile_id_t id, bool emergency) /*< no locking
|
|||||||
{
|
{
|
||||||
CHK_LOGMANAGER(lm);
|
CHK_LOGMANAGER(lm);
|
||||||
|
|
||||||
if (emergency || logfile_set_enabled(id, false))
|
|
||||||
{
|
|
||||||
lm->lm_enabled_logfiles &= ~id;
|
lm->lm_enabled_logfiles &= ~id;
|
||||||
/**
|
/**
|
||||||
* Set global variable
|
* Set global variable
|
||||||
*/
|
*/
|
||||||
lm_enabled_logfiles_bitmask = lm->lm_enabled_logfiles;
|
lm_enabled_logfiles_bitmask = lm->lm_enabled_logfiles;
|
||||||
}
|
|
||||||
|
|
||||||
logmanager_unregister();
|
logmanager_unregister();
|
||||||
rval = 0;
|
rval = 0;
|
||||||
@ -1204,64 +1197,6 @@ static int skygw_log_disable_raw(logfile_id_t id, bool emergency) /*< no locking
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static bool logfile_set_enabled(logfile_id_t id, bool val)
|
|
||||||
{
|
|
||||||
bool rval = false;
|
|
||||||
|
|
||||||
CHK_LOGMANAGER(lm);
|
|
||||||
|
|
||||||
if (logmanager_is_valid_id(id))
|
|
||||||
{
|
|
||||||
if (!log_config.use_stdout)
|
|
||||||
{
|
|
||||||
const char *name;
|
|
||||||
|
|
||||||
switch (id)
|
|
||||||
{
|
|
||||||
default:
|
|
||||||
case LOGFILE_ERROR:
|
|
||||||
name = "LOGFILE_ERROR";
|
|
||||||
break;
|
|
||||||
|
|
||||||
case LOGFILE_MESSAGE:
|
|
||||||
name = "LOGFILE_MESSAGE";
|
|
||||||
break;
|
|
||||||
|
|
||||||
case LOGFILE_TRACE:
|
|
||||||
name = "LOGFILE_TRACE";
|
|
||||||
break;
|
|
||||||
|
|
||||||
case LOGFILE_DEBUG:
|
|
||||||
name = "LOGFILE_DEBUG";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char FORMAT[] = "The logging of %s messages is %s.";
|
|
||||||
const char *action;
|
|
||||||
|
|
||||||
if (val)
|
|
||||||
{
|
|
||||||
action = "enabled";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
action = "disabled";
|
|
||||||
}
|
|
||||||
|
|
||||||
MXS_NOTICE(FORMAT, name, action);
|
|
||||||
}
|
|
||||||
|
|
||||||
rval = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
MXS_ERROR("Invalid logfile id %d.", id);
|
|
||||||
ss_dassert(!true);
|
|
||||||
}
|
|
||||||
|
|
||||||
return rval;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set log augmentation.
|
* Set log augmentation.
|
||||||
*
|
*
|
||||||
@ -2309,7 +2244,7 @@ static bool thr_flush_file(logmanager_t *lm, filewriter_t *fwr)
|
|||||||
err,
|
err,
|
||||||
strerror_r(err, errbuf, sizeof(errbuf)));
|
strerror_r(err, errbuf, sizeof(errbuf)));
|
||||||
/** Force log off */
|
/** Force log off */
|
||||||
skygw_log_disable_raw(LOGFILE_ERROR, true);
|
skygw_log_disable(LOGFILE_ERROR);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Reset buffer's counters and mark
|
* Reset buffer's counters and mark
|
||||||
@ -2702,44 +2637,50 @@ int mxs_log_rotate()
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool convert_priority_to_file(int priority, logfile_id_t* idp, const char** textp)
|
static logfile_id_t priority_to_file_id(int priority)
|
||||||
{
|
{
|
||||||
bool converted = true;
|
|
||||||
|
|
||||||
*idp = (logfile_id_t) -1;
|
|
||||||
*textp = NULL;
|
|
||||||
|
|
||||||
switch (priority)
|
switch (priority)
|
||||||
{
|
{
|
||||||
case LOG_DEBUG:
|
case LOG_DEBUG:
|
||||||
*idp = LOGFILE_DEBUG;
|
return LOGFILE_DEBUG;
|
||||||
break;
|
|
||||||
case LOG_INFO:
|
case LOG_INFO:
|
||||||
*idp = LOGFILE_TRACE;
|
return LOGFILE_TRACE;
|
||||||
break;
|
|
||||||
case LOG_NOTICE:
|
case LOG_NOTICE:
|
||||||
*idp = LOGFILE_MESSAGE;
|
return LOGFILE_MESSAGE;
|
||||||
break;
|
|
||||||
case LOG_ERR:
|
case LOG_ERR:
|
||||||
*idp = LOGFILE_ERROR;
|
|
||||||
break;
|
|
||||||
case LOG_WARNING:
|
case LOG_WARNING:
|
||||||
*textp = "LOG_WARNING";
|
|
||||||
break;
|
|
||||||
case LOG_CRIT:
|
case LOG_CRIT:
|
||||||
*textp = "LOG_CRIT";
|
|
||||||
break;
|
|
||||||
case LOG_ALERT:
|
case LOG_ALERT:
|
||||||
*textp = "LOG_ALERT";
|
|
||||||
break;
|
|
||||||
case LOG_EMERG:
|
case LOG_EMERG:
|
||||||
*textp = "LOG_EMERG";
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
converted = false;
|
return LOGFILE_ERROR;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return converted;
|
static const char* priority_name(int priority)
|
||||||
|
{
|
||||||
|
switch (priority)
|
||||||
|
{
|
||||||
|
case LOG_EMERG:
|
||||||
|
return "emercency";
|
||||||
|
case LOG_ALERT:
|
||||||
|
return "alert";
|
||||||
|
case LOG_CRIT:
|
||||||
|
return "critical";
|
||||||
|
case LOG_ERR:
|
||||||
|
return "error";
|
||||||
|
case LOG_WARNING:
|
||||||
|
return "warning";
|
||||||
|
case LOG_NOTICE:
|
||||||
|
return "notice";
|
||||||
|
case LOG_INFO:
|
||||||
|
return "informational";
|
||||||
|
case LOG_DEBUG:
|
||||||
|
return "debug";
|
||||||
|
default:
|
||||||
|
assert(!true);
|
||||||
|
return "unknown";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -2750,34 +2691,33 @@ static bool convert_priority_to_file(int priority, logfile_id_t* idp, const char
|
|||||||
*
|
*
|
||||||
* @return 0 if the priority was valid, -1 otherwise.
|
* @return 0 if the priority was valid, -1 otherwise.
|
||||||
*/
|
*/
|
||||||
int mxs_log_set_priority_enabled(int priority, bool enabled)
|
int mxs_log_set_priority_enabled(int priority, bool enable)
|
||||||
{
|
{
|
||||||
int rv = -1;
|
int rv = -1;
|
||||||
logfile_id_t id;
|
const char* text = (enable ? "enable" : "disable");
|
||||||
const char* text;
|
|
||||||
|
|
||||||
if (convert_priority_to_file(priority, &id, &text))
|
if ((priority & ~LOG_PRIMASK) == 0)
|
||||||
{
|
{
|
||||||
if (!text)
|
logfile_id_t id = priority_to_file_id(priority);
|
||||||
|
int bit = (1 << priority);
|
||||||
|
|
||||||
|
if (enable)
|
||||||
{
|
{
|
||||||
if (enabled)
|
// TODO: Put behind spinlock.
|
||||||
{
|
lm_enabled_priorities_bitmask |= bit;
|
||||||
rv = skygw_log_enable(id);
|
skygw_log_enable(id);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
rv = skygw_log_disable(id);
|
lm_enabled_priorities_bitmask &= ~bit;
|
||||||
|
skygw_log_disable(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MXS_NOTICE("The logging of %s messages has been %sd.", priority_name(priority), text);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
MXS_WARNING("Attempt to enable syslog priority %s, which is not available yet.", text);
|
MXS_ERROR("Attempt to %s unknown syslog priority %d.", text, priority);
|
||||||
rv = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
MXS_ERROR("Attempt to enable unknown syslog priority: %d", priority);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
|
|||||||
@ -27,6 +27,21 @@
|
|||||||
#define STRERROR_BUFLEN 512
|
#define STRERROR_BUFLEN 512
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
enum mxs_log_priorities
|
||||||
|
{
|
||||||
|
MXS_LOG_EMERG = (1 << LOG_EMERG),
|
||||||
|
MXS_LOG_ALERT = (1 << LOG_ALERT),
|
||||||
|
MXS_LOG_CRIT = (1 << LOG_CRIT),
|
||||||
|
MXS_LOG_ERR = (1 << LOG_ERR),
|
||||||
|
MXS_LOG_WARNING = (1 << LOG_WARNING),
|
||||||
|
MXS_LOG_NOTICE = (1 << LOG_NOTICE),
|
||||||
|
MXS_LOG_INFO = (1 << LOG_INFO),
|
||||||
|
MXS_LOG_DEBUG = (1 << LOG_DEBUG),
|
||||||
|
|
||||||
|
MXS_LOG_MASK = (MXS_LOG_EMERG | MXS_LOG_ALERT | MXS_LOG_CRIT | MXS_LOG_ERR |
|
||||||
|
MXS_LOG_WARNING | MXS_LOG_NOTICE | MXS_LOG_INFO | MXS_LOG_DEBUG),
|
||||||
|
};
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
BB_READY = 0x00,
|
BB_READY = 0x00,
|
||||||
@ -80,7 +95,6 @@ typedef struct log_info
|
|||||||
(log_ses_count[id] > 0 && \
|
(log_ses_count[id] > 0 && \
|
||||||
tls_log_info.li_enabled_logs & id)) ? true : false)
|
tls_log_info.li_enabled_logs & id)) ? true : false)
|
||||||
|
|
||||||
|
|
||||||
#define LOG_MAY_BE_ENABLED(id) (((lm_enabled_logfiles_bitmask & id) || \
|
#define LOG_MAY_BE_ENABLED(id) (((lm_enabled_logfiles_bitmask & id) || \
|
||||||
log_ses_count[id] > 0) ? true : false)
|
log_ses_count[id] > 0) ? true : false)
|
||||||
|
|
||||||
@ -119,6 +133,7 @@ typedef enum
|
|||||||
|
|
||||||
EXTERN_C_BLOCK_BEGIN
|
EXTERN_C_BLOCK_BEGIN
|
||||||
|
|
||||||
|
extern int lm_enabled_priorities_bitmask;
|
||||||
extern int lm_enabled_logfiles_bitmask;
|
extern int lm_enabled_logfiles_bitmask;
|
||||||
extern ssize_t log_ses_count[];
|
extern ssize_t log_ses_count[];
|
||||||
extern __thread log_info_t tls_log_info;
|
extern __thread log_info_t tls_log_info;
|
||||||
@ -140,9 +155,6 @@ int mxs_log_message(int priority,
|
|||||||
const char* file, int line, const char* function,
|
const char* file, int line, const char* function,
|
||||||
const char* format, ...);
|
const char* format, ...);
|
||||||
|
|
||||||
int skygw_log_enable(logfile_id_t id);
|
|
||||||
int skygw_log_disable(logfile_id_t id);
|
|
||||||
|
|
||||||
inline int mxs_log_id_to_priority(logfile_id_t id)
|
inline int mxs_log_id_to_priority(logfile_id_t id)
|
||||||
{
|
{
|
||||||
if (id & LOGFILE_ERROR) return LOG_ERR;
|
if (id & LOGFILE_ERROR) return LOG_ERR;
|
||||||
|
|||||||
@ -62,6 +62,38 @@ const int N_THR = 4;
|
|||||||
#define TEST_ERROR(msg)\
|
#define TEST_ERROR(msg)\
|
||||||
do { fprintf(stderr, "[%s:%d]: %s\n", basename(__FILE__), __LINE__, msg); } while (false)
|
do { fprintf(stderr, "[%s:%d]: %s\n", basename(__FILE__), __LINE__, msg); } while (false)
|
||||||
|
|
||||||
|
static logfile_id_t id_to_priority(logfile_id_t id)
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void skygw_log_enable(logfile_id_t id)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
|||||||
@ -23,6 +23,38 @@
|
|||||||
#include <skygw_utils.h>
|
#include <skygw_utils.h>
|
||||||
#include <log_manager.h>
|
#include <log_manager.h>
|
||||||
|
|
||||||
|
static logfile_id_t id_to_priority(logfile_id_t id)
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void skygw_log_enable(logfile_id_t id)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
int iterations = 0, i, interval = 10;
|
int iterations = 0, i, interval = 10;
|
||||||
|
|||||||
@ -1596,12 +1596,16 @@ config_get_feedback_data()
|
|||||||
|
|
||||||
static struct
|
static struct
|
||||||
{
|
{
|
||||||
char *logname;
|
char* name;
|
||||||
logfile_id_t logfile;
|
int priority;
|
||||||
|
char* replacement;
|
||||||
} lognames[] = {
|
} lognames[] = {
|
||||||
{ "log_messages", LOGFILE_MESSAGE },
|
{ "log_messages", LOG_NOTICE, "log_notice" }, // Deprecated
|
||||||
{ "log_trace", LOGFILE_TRACE },
|
{ "log_trace", LOG_INFO, "log_info" }, // Deprecated
|
||||||
{ "log_debug", LOGFILE_DEBUG },
|
{ "log_debug", LOG_DEBUG, NULL },
|
||||||
|
{ "log_warning", LOG_WARNING, NULL },
|
||||||
|
{ "log_notice", LOG_NOTICE, NULL },
|
||||||
|
{ "log_info", LOG_INFO, NULL },
|
||||||
{ NULL, 0 }
|
{ NULL, 0 }
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
@ -1681,18 +1685,18 @@ handle_global_item(const char *name, const char *value)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for (i = 0; lognames[i].logname; i++)
|
for (i = 0; lognames[i].name; i++)
|
||||||
{
|
{
|
||||||
if (strcasecmp(name, lognames[i].logname) == 0)
|
if (strcasecmp(name, lognames[i].name) == 0)
|
||||||
{
|
{
|
||||||
if (config_truth_value((char*)value))
|
if (lognames[i].replacement)
|
||||||
{
|
{
|
||||||
skygw_log_enable(lognames[i].logfile);
|
MXS_WARNING("In the configuration file the use of '%s' is deprecated, "
|
||||||
}
|
"use '%s' instead.",
|
||||||
else
|
lognames[i].name, lognames[i].replacement);
|
||||||
{
|
|
||||||
skygw_log_disable(lognames[i].logfile);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mxs_log_set_priority_enabled(lognames[i].priority, config_truth_value((char*)value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -125,13 +125,8 @@ int main(int argc, char **argv) {
|
|||||||
num_args = optind;
|
num_args = optind;
|
||||||
|
|
||||||
mxs_log_init(NULL, NULL, LOG_TARGET_DEFAULT);
|
mxs_log_init(NULL, NULL, LOG_TARGET_DEFAULT);
|
||||||
|
|
||||||
mxs_log_set_augmentation(0);
|
mxs_log_set_augmentation(0);
|
||||||
|
mxs_log_set_priority_enabled(LOG_DEBUG, debug_out);
|
||||||
if (!debug_out)
|
|
||||||
skygw_log_disable(LOGFILE_DEBUG);
|
|
||||||
else
|
|
||||||
skygw_log_enable(LOGFILE_DEBUG);
|
|
||||||
|
|
||||||
if ((inst = calloc(1, sizeof(ROUTER_INSTANCE))) == NULL) {
|
if ((inst = calloc(1, sizeof(ROUTER_INSTANCE))) == NULL) {
|
||||||
LOGIF(LE, (skygw_log_write_flush(LOGFILE_ERROR,
|
LOGIF(LE, (skygw_log_write_flush(LOGFILE_ERROR,
|
||||||
|
|||||||
@ -91,10 +91,10 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
mxs_log_init(NULL, NULL, LOG_TARGET_DEFAULT);
|
mxs_log_init(NULL, NULL, LOG_TARGET_DEFAULT);
|
||||||
|
|
||||||
skygw_log_disable(LOGFILE_DEBUG);
|
mxs_log_set_priority_enabled(LOG_DEBUG, false);
|
||||||
skygw_log_disable(LOGFILE_TRACE);
|
mxs_log_set_priority_enabled(LOG_INFO, false);
|
||||||
skygw_log_disable(LOGFILE_ERROR);
|
mxs_log_set_priority_enabled(LOG_NOTICE, false);
|
||||||
skygw_log_disable(LOGFILE_MESSAGE);
|
mxs_log_set_priority_enabled(LOG_ERR, false);
|
||||||
|
|
||||||
service = service_alloc("test_service", "binlogrouter");
|
service = service_alloc("test_service", "binlogrouter");
|
||||||
service->credentials.name = strdup("foo");
|
service->credentials.name = strdup("foo");
|
||||||
|
|||||||
@ -410,22 +410,20 @@ struct subcommand enableoptions[] = {
|
|||||||
"log",
|
"log",
|
||||||
1,
|
1,
|
||||||
enable_log_action,
|
enable_log_action,
|
||||||
"Enable Log options for MaxScale, options trace | error | "
|
"[deprecated] Enable Log options for MaxScale, options 'trace' | 'error' | 'message'."
|
||||||
"message E.g. enable log message.",
|
"E.g. 'enable log message'.",
|
||||||
"Enable Log options for MaxScale, options trace | error | "
|
"[deprecated] Enable Log options for MaxScale, options 'trace' | 'error' | 'message'."
|
||||||
"message E.g. enable log message.",
|
"E.g. 'enable log message'.",
|
||||||
{ARG_TYPE_STRING, 0, 0}
|
{ARG_TYPE_STRING, 0, 0}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"log-priority",
|
"log-priority",
|
||||||
1,
|
1,
|
||||||
enable_log_priority,
|
enable_log_priority,
|
||||||
"Enable log priority for MaxScale; options LOG_ERR | "
|
"Enable a logging priority; options 'err' | 'warning' | 'notice' | 'info' | 'debug'. "
|
||||||
"LOG_WARNING | LOG_NOTICE | LOG_INFO | LOG_DEBUG. "
|
"E.g.: 'enable log-priority info'.",
|
||||||
"E.g.: enable log-priority LOG_INFO.",
|
"Enable a logging priority; options 'err' | 'warning' | 'notice' | 'info' | 'debug'. "
|
||||||
"Enable log priority for MaxScale; options LOG_ERR | "
|
"E.g.: 'enable log-priority info'.",
|
||||||
"LOG_WARNING | LOG_NOTICE | LOG_INFO | LOG_DEBUG. "
|
|
||||||
"E.g.: enable log-priority LOG_INFO.",
|
|
||||||
{ARG_TYPE_STRING, 0, 0}
|
{ARG_TYPE_STRING, 0, 0}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -482,22 +480,20 @@ struct subcommand disableoptions[] = {
|
|||||||
"log",
|
"log",
|
||||||
1,
|
1,
|
||||||
disable_log_action,
|
disable_log_action,
|
||||||
"Disable Log for MaxScale, Options: debug | trace | error | message "
|
"[deprecated] Disable Log for MaxScale, Options: 'debug' | 'trace' | 'error' | 'message'."
|
||||||
"E.g. disable log debug",
|
"E.g. 'disable log debug'.",
|
||||||
"Disable Log for MaxScale, Options: debug | trace | error | message "
|
"[deprecated] Disable Log for MaxScale, Options: 'debug' | 'trace' | 'error' | 'message'."
|
||||||
"E.g. disable log debug",
|
"E.g. 'disable log debug'.",
|
||||||
{ARG_TYPE_STRING, 0, 0}
|
{ARG_TYPE_STRING, 0, 0}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"log-priority",
|
"log-priority",
|
||||||
1,
|
1,
|
||||||
disable_log_priority,
|
disable_log_priority,
|
||||||
"Disable log priority for MaxScale; options LOG_ERR | "
|
"Disable a logging priority; options 'err' | 'warning' | 'notice' | 'info' | 'debug'. "
|
||||||
"LOG_WARNING | LOG_NOTICE | LOG_INFO | LOG_DEBUG. "
|
"E.g.: 'disable log-priority info'.",
|
||||||
"E.g.: enable log-priority LOG_INFO.",
|
"Disable a logging priority; options 'err' | 'warning' | 'notice' | 'info' | 'debug'. "
|
||||||
"Disable log priority for MaxScale; options LOG_ERR | "
|
"E.g.: 'disable log-priority info'.",
|
||||||
"LOG_WARNING | LOG_NOTICE | LOG_INFO | LOG_DEBUG. "
|
|
||||||
"E.g.: enable log-priority LOG_INFO.",
|
|
||||||
{ARG_TYPE_STRING, 0, 0}
|
{ARG_TYPE_STRING, 0, 0}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -962,7 +958,7 @@ execute_cmd(CLI_SESSION *cli)
|
|||||||
dcb_printf(dcb, "Available options to the %s command:\n", args[1]);
|
dcb_printf(dcb, "Available options to the %s command:\n", args[1]);
|
||||||
for (j = 0; cmds[i].options[j].arg1; j++)
|
for (j = 0; cmds[i].options[j].arg1; j++)
|
||||||
{
|
{
|
||||||
dcb_printf(dcb, " %-10s %s\n", cmds[i].options[j].arg1,
|
dcb_printf(dcb, " %-12s %s\n", cmds[i].options[j].arg1,
|
||||||
cmds[i].options[j].help);
|
cmds[i].options[j].help);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1449,98 +1445,87 @@ static void disable_sess_log_action(DCB *dcb, char *arg1, char *arg2)
|
|||||||
dcb_printf(dcb, "Session not found: %s\n", arg2);
|
dcb_printf(dcb, "Session not found: %s\n", arg2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct log_action_entry
|
||||||
|
{
|
||||||
|
const char* name;
|
||||||
|
int priority;
|
||||||
|
const char* replacement;
|
||||||
|
};
|
||||||
|
|
||||||
|
static bool get_log_action(const char* name, struct log_action_entry* entryp)
|
||||||
|
{
|
||||||
|
static const struct log_action_entry entries[] =
|
||||||
|
{
|
||||||
|
{ "debug", LOG_DEBUG, "debug" },
|
||||||
|
{ "trace", LOG_INFO, "info" },
|
||||||
|
{ "message", LOG_NOTICE, "notice" },
|
||||||
|
{ "error", LOG_ERR, "err" }
|
||||||
|
};
|
||||||
|
const int n_entries = sizeof(entries) / sizeof(entries[0]);
|
||||||
|
|
||||||
|
bool found = false;
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
|
while (!found && (i < n_entries))
|
||||||
|
{
|
||||||
|
if (strcmp(name, entries[i].name) == 0)
|
||||||
|
{
|
||||||
|
*entryp = entries[i];
|
||||||
|
found = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
|
||||||
|
return found;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The log enable action
|
* The log enable action
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static void enable_log_action(DCB *dcb, char *arg1)
|
static void enable_log_action(DCB *dcb, char *arg1)
|
||||||
{
|
{
|
||||||
logfile_id_t type = -1;
|
struct log_action_entry entry;
|
||||||
int max_len = strlen("message");
|
|
||||||
const char* priority;
|
|
||||||
|
|
||||||
if (strncmp(arg1, "debug", max_len) == 0)
|
if (get_log_action(arg1, &entry))
|
||||||
{
|
{
|
||||||
type = LOGFILE_DEBUG;
|
mxs_log_set_priority_enabled(entry.priority, true);
|
||||||
priority = "LOG_DEBUG";
|
|
||||||
}
|
|
||||||
else if (strncmp(arg1, "trace", max_len) == 0)
|
|
||||||
{
|
|
||||||
type = LOGFILE_TRACE;
|
|
||||||
priority = "LOG_INFO";
|
|
||||||
}
|
|
||||||
else if (strncmp(arg1, "error", max_len) == 0)
|
|
||||||
{
|
|
||||||
type = LOGFILE_ERROR;
|
|
||||||
priority = "LOG_ERR";
|
|
||||||
}
|
|
||||||
else if (strncmp(arg1, "message", max_len) == 0)
|
|
||||||
{
|
|
||||||
type = LOGFILE_MESSAGE;
|
|
||||||
priority = "LOG_NOTICE";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (type != -1)
|
|
||||||
{
|
|
||||||
skygw_log_enable(type);
|
|
||||||
dcb_printf(dcb,
|
dcb_printf(dcb,
|
||||||
"'enable log %s' is accepted but deprecated, use 'enable log-priority %s' instead.\n",
|
"'enable log %s' is accepted but deprecated, use 'enable log-priority %s' instead.\n",
|
||||||
arg1, priority);
|
arg1, entry.replacement);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
dcb_printf(dcb, "%s is not supported for enable log\n", arg1);
|
dcb_printf(dcb, "'%s' is not supported for enable log\n", arg1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The log disable action
|
* The log disable action
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static void disable_log_action(DCB *dcb, char *arg1)
|
static void disable_log_action(DCB *dcb, char *arg1)
|
||||||
{
|
{
|
||||||
logfile_id_t type = -1;
|
struct log_action_entry entry;
|
||||||
int max_len = strlen("message");
|
|
||||||
const char* priority;
|
|
||||||
|
|
||||||
if (strncmp(arg1, "debug", max_len) == 0)
|
if (get_log_action(arg1, &entry))
|
||||||
{
|
{
|
||||||
type = LOGFILE_DEBUG;
|
mxs_log_set_priority_enabled(entry.priority, false);
|
||||||
priority = "LOG_DEBUG";
|
|
||||||
}
|
|
||||||
else if (strncmp(arg1, "trace", max_len) == 0)
|
|
||||||
{
|
|
||||||
type = LOGFILE_TRACE;
|
|
||||||
priority = "LOG_INFO";
|
|
||||||
}
|
|
||||||
else if (strncmp(arg1, "error", max_len) == 0)
|
|
||||||
{
|
|
||||||
type = LOGFILE_ERROR;
|
|
||||||
priority = "LOG_ERR";
|
|
||||||
}
|
|
||||||
else if (strncmp(arg1, "message", max_len) == 0)
|
|
||||||
{
|
|
||||||
type = LOGFILE_MESSAGE;
|
|
||||||
priority = "LOG_NOTICE";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (type != -1)
|
|
||||||
{
|
|
||||||
skygw_log_disable(type);
|
|
||||||
dcb_printf(dcb,
|
dcb_printf(dcb,
|
||||||
"'disable log %s' is accepted but deprecated, use 'disable log-priority %s' instead.\n",
|
"'disable log %s' is accepted but deprecated, use 'enable log-priority %s' instead.\n",
|
||||||
arg1, priority);
|
arg1, entry.replacement);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
dcb_printf(dcb, "%s is not supported for disable log\n", arg1);
|
dcb_printf(dcb, "'%s' is not supported for 'disable log'\n", arg1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct log_priority_entry
|
struct log_priority_entry
|
||||||
{
|
{
|
||||||
int priority;
|
|
||||||
const char* name;
|
const char* name;
|
||||||
|
int priority;
|
||||||
};
|
};
|
||||||
|
|
||||||
static int compare_log_priority_entries(const void* l, const void* r)
|
static int compare_log_priority_entries(const void* l, const void* r)
|
||||||
@ -1556,16 +1541,16 @@ static int string_to_priority(const char* name)
|
|||||||
static const struct log_priority_entry LOG_PRIORITY_ENTRIES[] =
|
static const struct log_priority_entry LOG_PRIORITY_ENTRIES[] =
|
||||||
{
|
{
|
||||||
// NOTE: If you make changes to this array, ensure that it remains alphabetically ordered.
|
// NOTE: If you make changes to this array, ensure that it remains alphabetically ordered.
|
||||||
{ LOG_DEBUG, "LOG_DEBUG" },
|
{ "debug", LOG_DEBUG },
|
||||||
{ LOG_ERR, "LOG_ERR" },
|
{ "err", LOG_ERR },
|
||||||
{ LOG_INFO, "LOG_INFO" },
|
{ "info", LOG_INFO },
|
||||||
{ LOG_NOTICE, "LOG_NOTICE" },
|
{ "notice", LOG_NOTICE },
|
||||||
{ LOG_WARNING, "LOG_WARNING" },
|
{ "warning", LOG_WARNING },
|
||||||
};
|
};
|
||||||
|
|
||||||
const size_t N_LOG_PRIORITY_ENTRIES = sizeof(LOG_PRIORITY_ENTRIES) / sizeof(LOG_PRIORITY_ENTRIES[0]);
|
const size_t N_LOG_PRIORITY_ENTRIES = sizeof(LOG_PRIORITY_ENTRIES) / sizeof(LOG_PRIORITY_ENTRIES[0]);
|
||||||
|
|
||||||
struct log_priority_entry key = { -1, name };
|
struct log_priority_entry key = { name, -1 };
|
||||||
struct log_priority_entry* result = bsearch(&key,
|
struct log_priority_entry* result = bsearch(&key,
|
||||||
LOG_PRIORITY_ENTRIES,
|
LOG_PRIORITY_ENTRIES,
|
||||||
N_LOG_PRIORITY_ENTRIES,
|
N_LOG_PRIORITY_ENTRIES,
|
||||||
@ -1589,7 +1574,7 @@ static void enable_log_priority(DCB *dcb, char *arg1)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
dcb_printf(dcb, "%s is not a supported log priority\n", arg1);
|
dcb_printf(dcb, "'%s' is not a supported log priority\n", arg1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1607,7 +1592,7 @@ static void disable_log_priority(DCB *dcb, char *arg1)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
dcb_printf(dcb, "%s is not a supported log priority\n", arg1);
|
dcb_printf(dcb, "'%s' is not a supported log priority\n", arg1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user