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;
|
||||
|
||||
/**
|
||||
* 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
|
||||
* 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_unregister(blockbuf_t* bb);
|
||||
static bool logfile_set_enabled(logfile_id_t id, bool val);
|
||||
static char* add_slash(char* str);
|
||||
|
||||
static bool check_file_and_path(char* filename,
|
||||
@ -318,7 +323,6 @@ static bool check_file_and_path(char* filename,
|
||||
bool do_log);
|
||||
|
||||
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);
|
||||
void flushall_logfiles(bool flush);
|
||||
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;
|
||||
|
||||
@ -1158,14 +1162,11 @@ int skygw_log_enable(logfile_id_t id)
|
||||
{
|
||||
CHK_LOGMANAGER(lm);
|
||||
|
||||
if (logfile_set_enabled(id, true))
|
||||
{
|
||||
lm->lm_enabled_logfiles |= id;
|
||||
/**
|
||||
* Set global variable
|
||||
*/
|
||||
lm_enabled_logfiles_bitmask = lm->lm_enabled_logfiles;
|
||||
}
|
||||
lm->lm_enabled_logfiles |= id;
|
||||
/**
|
||||
* Set global variable
|
||||
*/
|
||||
lm_enabled_logfiles_bitmask = lm->lm_enabled_logfiles;
|
||||
|
||||
logmanager_unregister();
|
||||
rval = 0;
|
||||
@ -1174,12 +1175,7 @@ int skygw_log_enable(logfile_id_t id)
|
||||
return rval;
|
||||
}
|
||||
|
||||
int skygw_log_disable(logfile_id_t id) /*< no locking */
|
||||
{
|
||||
return skygw_log_disable_raw(id, false);
|
||||
}
|
||||
|
||||
static int skygw_log_disable_raw(logfile_id_t id, bool emergency) /*< no locking */
|
||||
static int skygw_log_disable(logfile_id_t id)
|
||||
{
|
||||
bool rval = -1;
|
||||
|
||||
@ -1187,14 +1183,11 @@ static int skygw_log_disable_raw(logfile_id_t id, bool emergency) /*< no locking
|
||||
{
|
||||
CHK_LOGMANAGER(lm);
|
||||
|
||||
if (emergency || logfile_set_enabled(id, false))
|
||||
{
|
||||
lm->lm_enabled_logfiles &= ~id;
|
||||
/**
|
||||
* Set global variable
|
||||
*/
|
||||
lm_enabled_logfiles_bitmask = lm->lm_enabled_logfiles;
|
||||
}
|
||||
lm->lm_enabled_logfiles &= ~id;
|
||||
/**
|
||||
* Set global variable
|
||||
*/
|
||||
lm_enabled_logfiles_bitmask = lm->lm_enabled_logfiles;
|
||||
|
||||
logmanager_unregister();
|
||||
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.
|
||||
*
|
||||
@ -2309,7 +2244,7 @@ static bool thr_flush_file(logmanager_t *lm, filewriter_t *fwr)
|
||||
err,
|
||||
strerror_r(err, errbuf, sizeof(errbuf)));
|
||||
/** Force log off */
|
||||
skygw_log_disable_raw(LOGFILE_ERROR, true);
|
||||
skygw_log_disable(LOGFILE_ERROR);
|
||||
}
|
||||
/**
|
||||
* Reset buffer's counters and mark
|
||||
@ -2702,44 +2637,50 @@ int mxs_log_rotate()
|
||||
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)
|
||||
{
|
||||
case LOG_DEBUG:
|
||||
*idp = LOGFILE_DEBUG;
|
||||
break;
|
||||
return LOGFILE_DEBUG;
|
||||
case LOG_INFO:
|
||||
*idp = LOGFILE_TRACE;
|
||||
break;
|
||||
return LOGFILE_TRACE;
|
||||
case LOG_NOTICE:
|
||||
*idp = LOGFILE_MESSAGE;
|
||||
break;
|
||||
return LOGFILE_MESSAGE;
|
||||
case LOG_ERR:
|
||||
*idp = LOGFILE_ERROR;
|
||||
break;
|
||||
case LOG_WARNING:
|
||||
*textp = "LOG_WARNING";
|
||||
break;
|
||||
case LOG_CRIT:
|
||||
*textp = "LOG_CRIT";
|
||||
break;
|
||||
case LOG_ALERT:
|
||||
*textp = "LOG_ALERT";
|
||||
break;
|
||||
case LOG_EMERG:
|
||||
*textp = "LOG_EMERG";
|
||||
break;
|
||||
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.
|
||||
*/
|
||||
int mxs_log_set_priority_enabled(int priority, bool enabled)
|
||||
int mxs_log_set_priority_enabled(int priority, bool enable)
|
||||
{
|
||||
int rv = -1;
|
||||
logfile_id_t id;
|
||||
const char* text;
|
||||
const char* text = (enable ? "enable" : "disable");
|
||||
|
||||
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)
|
||||
{
|
||||
rv = skygw_log_enable(id);
|
||||
}
|
||||
else
|
||||
{
|
||||
rv = skygw_log_disable(id);
|
||||
}
|
||||
// TODO: Put behind spinlock.
|
||||
lm_enabled_priorities_bitmask |= bit;
|
||||
skygw_log_enable(id);
|
||||
}
|
||||
else
|
||||
{
|
||||
MXS_WARNING("Attempt to enable syslog priority %s, which is not available yet.", text);
|
||||
rv = 0;
|
||||
lm_enabled_priorities_bitmask &= ~bit;
|
||||
skygw_log_disable(id);
|
||||
}
|
||||
|
||||
MXS_NOTICE("The logging of %s messages has been %sd.", priority_name(priority), text);
|
||||
}
|
||||
else
|
||||
{
|
||||
MXS_ERROR("Attempt to enable unknown syslog priority: %d", priority);
|
||||
MXS_ERROR("Attempt to %s unknown syslog priority %d.", text, priority);
|
||||
}
|
||||
|
||||
return rv;
|
||||
|
@ -27,6 +27,21 @@
|
||||
#define STRERROR_BUFLEN 512
|
||||
#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
|
||||
{
|
||||
BB_READY = 0x00,
|
||||
@ -80,7 +95,6 @@ typedef struct log_info
|
||||
(log_ses_count[id] > 0 && \
|
||||
tls_log_info.li_enabled_logs & id)) ? true : false)
|
||||
|
||||
|
||||
#define LOG_MAY_BE_ENABLED(id) (((lm_enabled_logfiles_bitmask & id) || \
|
||||
log_ses_count[id] > 0) ? true : false)
|
||||
|
||||
@ -119,6 +133,7 @@ typedef enum
|
||||
|
||||
EXTERN_C_BLOCK_BEGIN
|
||||
|
||||
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;
|
||||
@ -140,9 +155,6 @@ int mxs_log_message(int priority,
|
||||
const char* file, int line, const char* function,
|
||||
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)
|
||||
{
|
||||
if (id & LOGFILE_ERROR) return LOG_ERR;
|
||||
|
@ -62,6 +62,38 @@ 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)
|
||||
{
|
||||
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 err = 0;
|
||||
|
@ -23,6 +23,38 @@
|
||||
#include <skygw_utils.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 iterations = 0, i, interval = 10;
|
||||
|
Reference in New Issue
Block a user