Logging target must be explicitly defined.

Whether the log-file should be written to the filesystem or to
shared memory must now be explicitly defined when calling
skygw_logmanager_init() (instead of passing that via the argc/argv
construct).

Also, the meaning of '-l' when invoking maxscale has been changed.

Earlier -l [file|shm] specified whether the trace and debug logs
should be written to shared memory (while the error and message
logs always were written to the filesystem) and the _default_
was to write them to shared memory.

Now, with only one file, '-l' has still the same meaning, but it
decides whether the one and only logfile should be written to shared
memory, or the filesystem and the _default_ is to write it to the
filesystem.
This commit is contained in:
Johan Wikman
2015-11-09 15:53:22 +02:00
parent 90a8646ac2
commit 55dbaa49c0
11 changed files with 58 additions and 86 deletions

View File

@ -90,8 +90,6 @@ ssize_t log_ses_count[LOGFILE_LAST] = {0};
*/
const char* shm_pathname_prefix = "/dev/shm/";
/** Logfile ids from call argument '-s' */
char* shmem_id_str = NULL;
/** Errors are written to syslog too by default */
char* syslog_id_str = strdup("LOGFILE_ERROR");
char* syslog_ident_str = NULL;
@ -231,6 +229,7 @@ struct logmanager
fnames_conf_t lm_fnames_conf;
logfile_t lm_logfile;
filewriter_t lm_filewriter;
log_target_t lm_target;
#if defined(SS_DEBUG)
skygw_chk_t lm_chk_tail;
#endif
@ -274,7 +273,7 @@ static void* thr_filewriter_fun(void* data);
static logfile_t* logmanager_get_logfile(logmanager_t* lm);
static bool logmanager_register(bool writep);
static void logmanager_unregister(void);
static bool logmanager_init_nomutex(const char* logdir, int argc, char* argv[]);
static bool logmanager_init_nomutex(const char* logdir, log_target_t target, int argc, char* argv[]);
static void logmanager_done_nomutex(void);
static bool logmanager_is_valid_id(logfile_id_t id);
@ -305,7 +304,7 @@ static int find_last_seqno(strpart_t* parts, int seqno, int seqnoidx);
void flushall_logfiles(bool flush);
bool thr_flushall_check();
static bool logmanager_init_nomutex(const char* logdir, int argc, char* argv[])
static bool logmanager_init_nomutex(const char* logdir, log_target_t target, int argc, char* argv[])
{
fnames_conf_t* fn;
filewriter_t* fw;
@ -319,6 +318,8 @@ static bool logmanager_init_nomutex(const char* logdir, int argc, char* argv[])
err = 1;
goto return_succp;
}
lm->lm_target = (target == LOG_TARGET_DEFAULT ? LOG_TARGET_FS : target);
#if defined(SS_DEBUG)
lm->lm_chk_top = CHK_NUM_LOGMANAGER;
lm->lm_chk_tail = CHK_NUM_LOGMANAGER;
@ -414,13 +415,15 @@ return_succp:
* Initializes log managing routines in MariaDB Corporation MaxScale.
*
* @param logdir The directory for the log file. If NULL logging will be made to stdout.
* @param argc number of arguments in argv array
* @param argv arguments array
* @param target Whether the log should be written to filesystem or shared memory.
* Meaningless if logdir is NULL.
* @param argc Number of arguments in argv array.
* @param argv Arguments array.
*
* @return true if succeed, otherwise false
*
*/
bool skygw_logmanager_init(const char* logdir, int argc, char* argv[])
bool skygw_logmanager_init(const char* logdir, log_target_t target, int argc, char* argv[])
{
bool succp = false;
@ -432,7 +435,7 @@ bool skygw_logmanager_init(const char* logdir, int argc, char* argv[])
goto return_succp;
}
succp = logmanager_init_nomutex(logdir, argc, argv);
succp = logmanager_init_nomutex(logdir, target, argc, argv);
return_succp:
release_lock(&lmlock);
@ -1620,7 +1623,7 @@ static bool logmanager_register(bool writep)
// If someone is logging before the log manager has been inited,
// or after the log manager has been finished, the messages are
// written to stdout.
succp = logmanager_init_nomutex(NULL, 0, NULL);
succp = logmanager_init_nomutex(NULL, LOG_TARGET_DEFAULT, 0, NULL);
}
}
/** if logmanager existed or was succesfully restarted, increase link */
@ -1687,8 +1690,7 @@ static bool fnames_conf_init(fnames_conf_t* fn,
const char* argstr =
"-h - help\n"
"-l <syslog log file ids> .......(no default)\n"
"-m <syslog ident> ............(argv[0])\n"
"-s <shmem log file ids> .......(no default)\n";
"-m <syslog ident> ............(argv[0])\n";
/**
* When init_started is set, clean must be done for it.
@ -1700,7 +1702,7 @@ static bool fnames_conf_init(fnames_conf_t* fn,
#endif
optind = 1; /**<! reset getopt index */
while ((opt = getopt(argc, argv, "+h:l:m:s:")) != -1)
while ((opt = getopt(argc, argv, "+h:l:m:")) != -1)
{
switch (opt)
{
@ -1724,10 +1726,6 @@ static bool fnames_conf_init(fnames_conf_t* fn,
syslog_ident_str = optarg;
break;
case 's':
/** record list of log file ids for later use */
shmem_id_str = optarg;
break;
case 'h':
default:
fprintf(stderr, "\nSupported arguments are (default)\n%s\n", argstr);
@ -1803,7 +1801,7 @@ return_conf_init:
static bool logfiles_init(logmanager_t* lm)
{
bool succp = true;
bool store_shmem;
bool store_shmem = (lm->lm_target == LOG_TARGET_SHMEM);
bool write_syslog;
/** Open syslog immediately. Print pid of loggind process. */
@ -1811,23 +1809,7 @@ static bool logfiles_init(logmanager_t* lm)
{
openlog(syslog_ident_str, LOG_PID | LOG_NDELAY, LOG_USER);
}
/**
* Initialize log file, pass softlink flag if necessary.
*/
/**
* Check if the file is stored in shared memory. If so,
* a symbolic link will be created to log directory.
*/
if (shmem_id_str != NULL &&
strcasestr(shmem_id_str, STRLOGID(LOGFILE_ERROR)) != NULL)
{
store_shmem = true;
}
else
{
store_shmem = false;
}
/**
* Check if file is also written to syslog.
*/

View File

@ -42,7 +42,6 @@ typedef enum
LOGFILE_LAST = LOGFILE_DEBUG
} logfile_id_t;
typedef enum
{
FILEWRITER_INIT,
@ -50,6 +49,13 @@ typedef enum
FILEWRITER_DONE
} filewriter_state_t;
typedef enum
{
LOG_TARGET_DEFAULT = 0,
LOG_TARGET_FS = 1, // File system
LOG_TARGET_SHMEM = 2, // Shared memory
} log_target_t;
/**
* Thread-specific logging information.
*/
@ -145,7 +151,7 @@ int mxs_log_rotate();
int mxs_log_enable_priority(int priority);
int mxs_log_disable_priority(int priority);
bool skygw_logmanager_init(const char* logdir, int argc, char* argv[]);
bool skygw_logmanager_init(const char* logdir, log_target_t target, int argc, char* argv[]);
void skygw_logmanager_done(void);
void skygw_logmanager_exit(void);

View File

@ -122,7 +122,7 @@ int main(int argc, char* argv[])
fprintf(stderr, "Couldn't register exit function.\n");
}
succp = skygw_logmanager_init("/tmp", log_argc, log_argv);
succp = skygw_logmanager_init("/tmp", LOG_TARGET_FS, log_argc, log_argv);
if (!succp)
{
@ -141,7 +141,7 @@ int main(int argc, char* argv[])
tm.tm_min,
tm.tm_sec);
skygw_logmanager_init("/tmp", log_argc, log_argv);
skygw_logmanager_init("/tmp", LOG_TARGET_FS, log_argc, log_argv);
logstr = ("First write with flush.");
err = skygw_log_write_flush(LOGFILE_ERROR, logstr);
@ -189,7 +189,7 @@ int main(int argc, char* argv[])
logstr = "Ph%dlip.";
err = skygw_log_write(LOGFILE_TRACE, logstr, 1);
skygw_logmanager_init("/tmp", log_argc, log_argv);
skygw_logmanager_init("/tmp", LOG_TARGET_FS, log_argc, log_argv);
logstr = ("A terrible error has occurred!");
err = skygw_log_write_flush(LOGFILE_ERROR, logstr);
@ -335,7 +335,7 @@ int main(int argc, char* argv[])
#if !defined(SS_DEBUG)
skygw_log_enable(LOGFILE_TRACE);
#endif
succp = skygw_logmanager_init("/tmp", log_argc, log_argv);
succp = skygw_logmanager_init("/tmp", LOG_TARGET_FS, log_argc, log_argv);
ss_dassert(succp);
logstr = ("\tTEST 3 - test enabling and disabling logs.");
@ -400,7 +400,7 @@ int main(int argc, char* argv[])
#endif /* TEST 3 */
#if defined(TEST4)
succp = skygw_logmanager_init("/tmp", log_argc, log_argv);
succp = skygw_logmanager_init("/tmp", LOG_TARGET_FS, log_argc, log_argv);
ss_dassert(succp);
#if !defined(SS_DEBUG)
skygw_log_enable(LOGFILE_TRACE);
@ -436,7 +436,7 @@ int main(int argc, char* argv[])
skygw_logmanager_done();
succp = skygw_logmanager_init("/tmp", log_argc, log_argv);
succp = skygw_logmanager_init("/tmp", LOG_TARGET_FS, log_argc, log_argv);
ss_dassert(succp);
#if !defined(SS_DEBUG)
skygw_log_enable(LOGFILE_TRACE);
@ -509,7 +509,7 @@ static void* thr_run(void* data)
char* logstr;
int err;
skygw_logmanager_init("/tmp", 0, NULL);
skygw_logmanager_init("/tmp", LOG_TARGET_FS, 0, NULL);
skygw_log_flush(LOGFILE_MESSAGE);
logstr = ("Hi, how are you?");
err = skygw_log_write(LOGFILE_MESSAGE, logstr);
@ -533,7 +533,7 @@ static void* thr_run(void* data)
}
ss_dassert(err == 0);
err = skygw_log_write(LOGFILE_MESSAGE, logstr);
skygw_logmanager_init("/tmp", 0, NULL);
skygw_logmanager_init("/tmp", LOG_TARGET_FS, 0, NULL);
logstr = ("Testing. One, two, three\n");
err = skygw_log_write(LOGFILE_ERROR, logstr);
if (err != 0)
@ -541,8 +541,8 @@ static void* thr_run(void* data)
TEST_ERROR("Error, log write failed.");
}
ss_dassert(err == 0);
skygw_logmanager_init("/tmp", 0, NULL);
skygw_logmanager_init("/tmp", 0, NULL);
skygw_logmanager_init("/tmp", LOG_TARGET_FS, 0, NULL);
skygw_logmanager_init("/tmp", LOG_TARGET_FS, 0, NULL);
skygw_log_flush(LOGFILE_ERROR);
logstr = ("For automatic and register variables, it is done each time the function or block is entered.");
@ -556,7 +556,7 @@ static void* thr_run(void* data)
}
ss_dassert(err == 0);
skygw_logmanager_done();
skygw_logmanager_init("/tmp", 0, NULL);
skygw_logmanager_init("/tmp", LOG_TARGET_FS, 0, NULL);
logstr = ("Rather more surprising, at least at first sight, is the fact that a reference "
"to a[i] can also be written as *(a+i). In evaluating a[i], C converts it to *(a+i) "
"immediately; the two forms are equivalent. Applying the operatos & to both parts "
@ -568,11 +568,11 @@ static void* thr_run(void* data)
TEST_ERROR("Error, log write failed.");
}
ss_dassert(err == 0);
skygw_logmanager_init("/tmp", 0, NULL);
skygw_logmanager_init("/tmp", LOG_TARGET_FS, 0, NULL);
skygw_logmanager_done();
skygw_log_flush(LOGFILE_ERROR);
skygw_logmanager_done();
skygw_logmanager_init("/tmp", 0, NULL);
skygw_logmanager_init("/tmp", LOG_TARGET_FS, 0, NULL);
logstr = ("..and you?");
err = skygw_log_write(LOGFILE_MESSAGE, logstr);
if (err != 0)
@ -581,7 +581,7 @@ static void* thr_run(void* data)
}
ss_dassert(err == 0);
skygw_logmanager_done();
skygw_logmanager_init("/tmp", 0, NULL);
skygw_logmanager_init("/tmp", LOG_TARGET_FS, 0, NULL);
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);
@ -592,7 +592,7 @@ static void* thr_run(void* data)
TEST_ERROR("Error, log write failed.");
}
ss_dassert(err == 0);
skygw_logmanager_init("/tmp", 0, NULL);
skygw_logmanager_init("/tmp", LOG_TARGET_FS, 0, NULL);
logstr = ("Rather more surprising, at least at first sight, is the fact that a reference to "
"a[i] can also be written as *(a+i). In evaluating a[i], C converts it to *(a+i) "
"immediately; the two forms are equivalent. Applying the operatos & to both parts "
@ -604,7 +604,7 @@ static void* thr_run(void* data)
TEST_ERROR("Error, log write failed.");
}
ss_dassert(err == 0);
skygw_logmanager_init("/tmp", 0, NULL);
skygw_logmanager_init("/tmp", LOG_TARGET_FS, 0, NULL);
logstr = ("..... and you too?");
err = skygw_log_write(LOGFILE_MESSAGE, logstr);
if (err != 0)
@ -613,7 +613,7 @@ static void* thr_run(void* data)
}
ss_dassert(err == 0);
skygw_logmanager_done();
skygw_logmanager_init("/tmp", 0, NULL);
skygw_logmanager_init("/tmp", LOG_TARGET_FS, 0, NULL);
#if !defined(SS_DEBUG)
skygw_log_enable(LOGFILE_TRACE);
#endif
@ -629,7 +629,7 @@ static void* thr_run(void* data)
}
ss_dassert(err == 0);
skygw_logmanager_done();
skygw_logmanager_init("/tmp", 0, NULL);
skygw_logmanager_init("/tmp", LOG_TARGET_FS, 0, NULL);
logstr = ("Testing. One, two, three, four\n");
err = skygw_log_write(LOGFILE_ERROR, logstr);
if (err != 0)
@ -638,7 +638,7 @@ static void* thr_run(void* data)
}
ss_dassert(err == 0);
skygw_logmanager_done();
skygw_logmanager_init("/tmp", 0, NULL);
skygw_logmanager_init("/tmp", LOG_TARGET_FS, 0, NULL);
logstr = ("Testing. One, two, three, .. where was I?\n");
err = skygw_log_write(LOGFILE_ERROR, logstr);
if (err != 0)
@ -647,7 +647,7 @@ static void* thr_run(void* data)
}
ss_dassert(err == 0);
skygw_logmanager_done();
skygw_logmanager_init("/tmp", 0, NULL);
skygw_logmanager_init("/tmp", LOG_TARGET_FS, 0, NULL);
skygw_logmanager_done();
simple_mutex_lock(td->mtx, true);
*td->nactive -= 1;

View File

@ -71,7 +71,7 @@ int main(int argc, char** argv)
iterations = atoi(argv[1]);
interval = atoi(argv[2]);
succp = skygw_logmanager_init(tmp, 1, optstr);
succp = skygw_logmanager_init(tmp, LOG_TARGET_FS, 1, optstr);
if (!succp)
{

View File

@ -1077,7 +1077,7 @@ int main(int argc, char **argv)
char* tmp_path;
char* tmp_var;
int option_index;
int logtofile = 0; /* Use shared memory or file */
log_target_t log_target = LOG_TARGET_FS;
int *syslog_enabled = &config_get_global_options()->syslog; /** Log to syslog */
int *maxscalelog_enabled = &config_get_global_options()->maxlog; /** Log with MaxScale */
ssize_t log_flush_timeout_ms = 0;
@ -1169,9 +1169,9 @@ int main(int argc, char **argv)
case 'l':
if (strncasecmp(optarg, "file", PATH_MAX) == 0)
logtofile = 1;
log_target = LOG_TARGET_FS;
else if (strncasecmp(optarg, "shm", PATH_MAX) == 0)
logtofile = 0;
log_target = LOG_TARGET_SHMEM;
else
{
char* logerr = "Configuration file argument "
@ -1703,8 +1703,6 @@ int main(int argc, char **argv)
* argv[0]
*/
{
char buf[1024];
char *argv[8];
bool succp;
if (mkdir(get_logdir(), 0777) != 0 && errno != EEXIST)
@ -1729,24 +1727,10 @@ int main(int argc, char **argv)
logmanager_enable_syslog(*syslog_enabled);
logmanager_enable_maxscalelog(*maxscalelog_enabled);
if (logtofile)
{
argv[1] = "-l"; /*< write to syslog */
/** Logs that should be syslogged */
argv[2] = "LOGFILE_MESSAGE,LOGFILE_ERROR"
"LOGFILE_DEBUG,LOGFILE_TRACE";
argv[3] = NULL;
succp = skygw_logmanager_init(get_logdir(), 3, argv);
}
else
{
argv[1] = "-s"; /*< store to shared memory */
argv[2] = "LOGFILE_DEBUG,LOGFILE_TRACE"; /*< to shm */
argv[3] = "-l"; /*< write to syslog */
argv[4] = "LOGFILE_MESSAGE,LOGFILE_ERROR"; /*< to syslog */
argv[5] = NULL;
succp = skygw_logmanager_init(get_logdir(), 5, argv);
}
char* log_argv[] = { "MaxScale", "-l", "LOGFILE_MESSAGE,LOGFILE_ERROR", NULL };
int log_argc = sizeof(log_argv) / sizeof(log_argv[0]) - 1;
succp = skygw_logmanager_init(get_logdir(), log_target, log_argc, log_argv);
if (!succp)
{

View File

@ -60,7 +60,7 @@ int main(int argc, char **argv)
arg_vector[0] = "logmanager";
arg_vector[1] = NULL;
skygw_logmanager_init(NULL, arg_count, arg_vector);
skygw_logmanager_init(NULL, LOG_TARGET_DEFAULT, arg_count, arg_vector);
free(arg_vector);
if (secrets_writeKeys(keyfile))

View File

@ -63,7 +63,7 @@ main(int argc, char **argv)
arg_vector[0] = "logmanager";
arg_vector[1] = NULL;
skygw_logmanager_init(NULL, arg_count, arg_vector);
skygw_logmanager_init(NULL, LOG_TARGET_DEFAULT, arg_count, arg_vector);
free(arg_vector);
pw = calloc(81, sizeof(char));

View File

@ -20,7 +20,7 @@ void init_test_env(char *path)
NULL
};
skygw_logmanager_init(logdir, argc, argv);
skygw_logmanager_init(logdir, LOG_TARGET_DEFAULT, argc, argv);
poll_init();
hkinit();
}

View File

@ -18,7 +18,7 @@ int harness_init(int argc, char** argv, HARNESS_INSTANCE** inst){
char** optstr;
if(!(argc == 2 && strcmp(argv[1],"-h") == 0)){
skygw_logmanager_init(NULL,0,NULL);
skygw_logmanager_init(NULL,LOG_TARGET_DEFAULT,0,NULL);
}
if(!(instance.head = calloc(1,sizeof(FILTERCHAIN))))
@ -55,7 +55,7 @@ int harness_init(int argc, char** argv, HARNESS_INSTANCE** inst){
optstr = (char**)malloc(sizeof(char*)*2);
optstr[0] = strdup("log_manager");
optstr[1] = NULL;
skygw_logmanager_init(tmp, 1, optstr);
skygw_logmanager_init(tmp, LOG_TARGET_DEFAULT, 1, optstr);
free(optstr);
rval = process_opts(argc,argv);

View File

@ -136,7 +136,7 @@ int main(int argc, char **argv) {
arg_vector[0] = "logmanager";
arg_vector[1] = NULL;
skygw_logmanager_init(NULL, arg_count, arg_vector);
skygw_logmanager_init(NULL, LOG_TARGET_DEFAULT, arg_count, arg_vector);
skygw_log_set_augmentation(0);

View File

@ -101,7 +101,7 @@ int main(int argc, char **argv) {
arg_vector[0] = "logmanager";
arg_vector[1] = NULL;
skygw_logmanager_init(NULL, arg_count,arg_vector);
skygw_logmanager_init(NULL, LOG_TARGET_DEFAULT, arg_count,arg_vector);
free(arg_vector);
skygw_log_disable(LOGFILE_DEBUG);