Log: No more argv parsing for log manager.

Earlier, the global setting for the syslog decided whether syslog
was enabled when skygw_logmanager_init was called, but not whether
logging to syslog actually was made.

Now syslog logging is enabled by default and the global setting
decides whether or not syslog logging actually is made. That is,
this opens up the possiblity for making it possible to turn on
and off sysloging at runtime.

Further, although the API led you to believe otherwise, it was
hardwired that LOGFILE_ERROR and LOGFILE_MESSAGE messages were
written to syslog.

The changed removed the need for passing an argv array explicitly.
This commit is contained in:
Johan Wikman
2015-11-10 14:37:49 +02:00
parent 0b7de96eff
commit acb0a523a7
11 changed files with 56 additions and 211 deletions

View File

@ -77,8 +77,6 @@ int main(int argc, char* argv[])
struct tm tm;
char c;
int nthr = N_THR;
int log_argc = 0;
char** log_argv = NULL;
while ((c = getopt(argc, argv, "t:")) != -1)
{
@ -122,7 +120,7 @@ int main(int argc, char* argv[])
fprintf(stderr, "Couldn't register exit function.\n");
}
succp = skygw_logmanager_init(NULL, "/tmp", LOG_TARGET_FS, log_argc, log_argv);
succp = skygw_logmanager_init(NULL, "/tmp", LOG_TARGET_FS);
if (!succp)
{
@ -141,7 +139,7 @@ int main(int argc, char* argv[])
tm.tm_min,
tm.tm_sec);
skygw_logmanager_init(NULL, "/tmp", LOG_TARGET_FS, log_argc, log_argv);
skygw_logmanager_init(NULL, "/tmp", LOG_TARGET_FS);
logstr = ("First write with flush.");
err = skygw_log_write_flush(LOGFILE_ERROR, logstr);
@ -189,7 +187,7 @@ int main(int argc, char* argv[])
logstr = "Ph%dlip.";
err = skygw_log_write(LOGFILE_TRACE, logstr, 1);
skygw_logmanager_init(NULL, "/tmp", LOG_TARGET_FS, log_argc, log_argv);
skygw_logmanager_init(NULL, "/tmp", LOG_TARGET_FS);
logstr = ("A terrible error has occurred!");
err = skygw_log_write_flush(LOGFILE_ERROR, logstr);
@ -335,7 +333,7 @@ int main(int argc, char* argv[])
#if !defined(SS_DEBUG)
skygw_log_enable(LOGFILE_TRACE);
#endif
succp = skygw_logmanager_init(NULL, "/tmp", LOG_TARGET_FS, log_argc, log_argv);
succp = skygw_logmanager_init(NULL, "/tmp", LOG_TARGET_FS);
ss_dassert(succp);
logstr = ("\tTEST 3 - test enabling and disabling logs.");
@ -400,7 +398,7 @@ int main(int argc, char* argv[])
#endif /* TEST 3 */
#if defined(TEST4)
succp = skygw_logmanager_init(NULL, "/tmp", LOG_TARGET_FS, log_argc, log_argv);
succp = skygw_logmanager_init(NULL, "/tmp", LOG_TARGET_FS);
ss_dassert(succp);
#if !defined(SS_DEBUG)
skygw_log_enable(LOGFILE_TRACE);
@ -436,7 +434,7 @@ int main(int argc, char* argv[])
skygw_logmanager_done();
succp = skygw_logmanager_init(NULL, "/tmp", LOG_TARGET_FS, log_argc, log_argv);
succp = skygw_logmanager_init(NULL, "/tmp", LOG_TARGET_FS);
ss_dassert(succp);
#if !defined(SS_DEBUG)
skygw_log_enable(LOGFILE_TRACE);
@ -509,7 +507,7 @@ static void* thr_run(void* data)
char* logstr;
int err;
skygw_logmanager_init(NULL, "/tmp", LOG_TARGET_FS, 0, NULL);
skygw_logmanager_init(NULL, "/tmp", LOG_TARGET_FS);
skygw_log_flush(LOGFILE_MESSAGE);
logstr = ("Hi, how are you?");
err = skygw_log_write(LOGFILE_MESSAGE, logstr);
@ -533,7 +531,7 @@ static void* thr_run(void* data)
}
ss_dassert(err == 0);
err = skygw_log_write(LOGFILE_MESSAGE, logstr);
skygw_logmanager_init(NULL, "/tmp", LOG_TARGET_FS, 0, NULL);
skygw_logmanager_init(NULL, "/tmp", LOG_TARGET_FS);
logstr = ("Testing. One, two, three\n");
err = skygw_log_write(LOGFILE_ERROR, logstr);
if (err != 0)
@ -541,8 +539,8 @@ static void* thr_run(void* data)
TEST_ERROR("Error, log write failed.");
}
ss_dassert(err == 0);
skygw_logmanager_init(NULL, "/tmp", LOG_TARGET_FS, 0, NULL);
skygw_logmanager_init(NULL, "/tmp", LOG_TARGET_FS, 0, NULL);
skygw_logmanager_init(NULL, "/tmp", LOG_TARGET_FS);
skygw_logmanager_init(NULL, "/tmp", LOG_TARGET_FS);
skygw_log_flush(LOGFILE_ERROR);
logstr = ("For automatic and register variables, it is done each time the function or block is entered.");
@ -556,7 +554,7 @@ static void* thr_run(void* data)
}
ss_dassert(err == 0);
skygw_logmanager_done();
skygw_logmanager_init(NULL, "/tmp", LOG_TARGET_FS, 0, NULL);
skygw_logmanager_init(NULL, "/tmp", LOG_TARGET_FS);
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 +566,11 @@ static void* thr_run(void* data)
TEST_ERROR("Error, log write failed.");
}
ss_dassert(err == 0);
skygw_logmanager_init(NULL, "/tmp", LOG_TARGET_FS, 0, NULL);
skygw_logmanager_init(NULL, "/tmp", LOG_TARGET_FS);
skygw_logmanager_done();
skygw_log_flush(LOGFILE_ERROR);
skygw_logmanager_done();
skygw_logmanager_init(NULL, "/tmp", LOG_TARGET_FS, 0, NULL);
skygw_logmanager_init(NULL, "/tmp", LOG_TARGET_FS);
logstr = ("..and you?");
err = skygw_log_write(LOGFILE_MESSAGE, logstr);
if (err != 0)
@ -581,7 +579,7 @@ static void* thr_run(void* data)
}
ss_dassert(err == 0);
skygw_logmanager_done();
skygw_logmanager_init(NULL, "/tmp", LOG_TARGET_FS, 0, NULL);
skygw_logmanager_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);
@ -592,7 +590,7 @@ static void* thr_run(void* data)
TEST_ERROR("Error, log write failed.");
}
ss_dassert(err == 0);
skygw_logmanager_init(NULL, "/tmp", LOG_TARGET_FS, 0, NULL);
skygw_logmanager_init(NULL, "/tmp", LOG_TARGET_FS);
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 +602,7 @@ static void* thr_run(void* data)
TEST_ERROR("Error, log write failed.");
}
ss_dassert(err == 0);
skygw_logmanager_init(NULL, "/tmp", LOG_TARGET_FS, 0, NULL);
skygw_logmanager_init(NULL, "/tmp", LOG_TARGET_FS);
logstr = ("..... and you too?");
err = skygw_log_write(LOGFILE_MESSAGE, logstr);
if (err != 0)
@ -613,7 +611,7 @@ static void* thr_run(void* data)
}
ss_dassert(err == 0);
skygw_logmanager_done();
skygw_logmanager_init(NULL, "/tmp", LOG_TARGET_FS, 0, NULL);
skygw_logmanager_init(NULL, "/tmp", LOG_TARGET_FS);
#if !defined(SS_DEBUG)
skygw_log_enable(LOGFILE_TRACE);
#endif
@ -629,7 +627,7 @@ static void* thr_run(void* data)
}
ss_dassert(err == 0);
skygw_logmanager_done();
skygw_logmanager_init(NULL, "/tmp", LOG_TARGET_FS, 0, NULL);
skygw_logmanager_init(NULL, "/tmp", LOG_TARGET_FS);
logstr = ("Testing. One, two, three, four\n");
err = skygw_log_write(LOGFILE_ERROR, logstr);
if (err != 0)
@ -638,7 +636,7 @@ static void* thr_run(void* data)
}
ss_dassert(err == 0);
skygw_logmanager_done();
skygw_logmanager_init(NULL, "/tmp", LOG_TARGET_FS, 0, NULL);
skygw_logmanager_init(NULL, "/tmp", LOG_TARGET_FS);
logstr = ("Testing. One, two, three, .. where was I?\n");
err = skygw_log_write(LOGFILE_ERROR, logstr);
if (err != 0)
@ -647,7 +645,7 @@ static void* thr_run(void* data)
}
ss_dassert(err == 0);
skygw_logmanager_done();
skygw_logmanager_init(NULL, "/tmp", LOG_TARGET_FS, 0, NULL);
skygw_logmanager_init(NULL, "/tmp", LOG_TARGET_FS);
skygw_logmanager_done();
simple_mutex_lock(td->mtx, true);
*td->nactive -= 1;