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++)
{