2017-09-16 04:10:14 +00:00
|
|
|
#include <qse/cmn/mem.h>
|
|
|
|
#include <qse/cmn/hwad.h>
|
|
|
|
#include <qse/si/log.h>
|
|
|
|
#include <qse/si/nwad.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2017-09-18 02:46:54 +00:00
|
|
|
static void t1_sub001 (qse_log_t* log)
|
|
|
|
{
|
|
|
|
static struct
|
|
|
|
{
|
|
|
|
const qse_char_t* name;
|
|
|
|
int pri;
|
|
|
|
} xtab[] =
|
|
|
|
{
|
|
|
|
{ QSE_T(""), 0 },
|
|
|
|
{ QSE_T(" "), 0 },
|
|
|
|
{ QSE_T("|"), 0 },
|
|
|
|
{ QSE_T("debug|xinfo|panic"), 0 },
|
|
|
|
{ QSE_T("debug|info|panic"), (QSE_LOG_DEBUG | QSE_LOG_INFO | QSE_LOG_PANIC) },
|
|
|
|
{ QSE_T("debug|notice|debug|panic"), (QSE_LOG_DEBUG | QSE_LOG_NOTICE | QSE_LOG_PANIC) },
|
|
|
|
{ QSE_T("notice"), QSE_LOG_NOTICE }
|
|
|
|
};
|
|
|
|
qse_size_t i;
|
|
|
|
qse_char_t buf[QSE_LOG_PRIORITY_LEN_MAX + 1];
|
|
|
|
qse_size_t len;
|
|
|
|
|
|
|
|
for (i = 0; i < QSE_COUNTOF(xtab); i++)
|
|
|
|
{
|
2017-09-18 04:06:58 +00:00
|
|
|
len = qse_make_log_priority_name (xtab[i].pri, QSE_T("|"), buf, QSE_COUNTOF(buf));
|
2017-09-18 02:46:54 +00:00
|
|
|
QSE_LOG3 (log, QSE_NULL, QSE_LOG_INFO, QSE_T("%x => %s [%d]"), xtab[i].pri, buf, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < QSE_COUNTOF(xtab); i++)
|
|
|
|
{
|
|
|
|
int pri;
|
2017-09-18 04:06:58 +00:00
|
|
|
if ((pri = qse_get_log_priority_by_name(xtab[i].name, QSE_T("|"))) == xtab[i].pri)
|
2017-09-18 02:46:54 +00:00
|
|
|
{
|
|
|
|
QSE_LOG2 (log, QSE_NULL, QSE_LOG_INFO, QSE_T("SUCCESS: %s => %x"), xtab[i].name, pri);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
QSE_LOG3 (log, QSE_NULL, QSE_LOG_INFO, QSE_T("FAILURE: %s => got %x expected %x"), xtab[i].name, pri, xtab[i].pri);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void t1 (void)
|
2017-09-16 04:10:14 +00:00
|
|
|
{
|
|
|
|
qse_log_t* log;
|
2019-11-09 00:32:34 +00:00
|
|
|
qse_log_target_data_t t;
|
2017-09-17 12:29:59 +00:00
|
|
|
#if defined(QSE_HAVE_INT128_T)
|
2017-09-16 04:10:14 +00:00
|
|
|
qse_int128_t q = 0x1234567890;
|
2017-09-17 12:29:59 +00:00
|
|
|
#elif defined(QSE_HAVE_INT64_T)
|
|
|
|
qse_int64_t q = 0x1234567890;
|
|
|
|
#else
|
|
|
|
qse_int32_t q = 0x12345678;
|
|
|
|
#endif
|
2017-09-16 04:10:14 +00:00
|
|
|
int i;
|
|
|
|
qse_nwad_t nwad;
|
|
|
|
|
|
|
|
t.file = QSE_T("/tmp/t3.log");
|
2017-09-16 07:01:03 +00:00
|
|
|
/*qse_strtonwad ("127.0.0.1:514", &nwad);*/
|
2017-09-16 09:16:15 +00:00
|
|
|
/*qse_strtonwad ("@/var/run/log", &nwad);*/
|
2017-09-17 12:29:59 +00:00
|
|
|
qse_strtonwad (QSE_T("@/dev/log"), &nwad);
|
2017-09-16 04:10:14 +00:00
|
|
|
qse_nwadtoskad (&nwad, &t.syslog_remote);
|
|
|
|
|
|
|
|
log = qse_log_open (QSE_MMGR_GETDFL(), 0, QSE_T("t3"),
|
2017-09-16 07:01:03 +00:00
|
|
|
QSE_LOG_INCLUDE_PID | QSE_LOG_HOST_IN_REMOTE_SYSLOG |
|
|
|
|
QSE_LOG_DEBUG |
|
|
|
|
QSE_LOG_CONSOLE | QSE_LOG_FILE | QSE_LOG_SYSLOG | QSE_LOG_SYSLOG_REMOTE, &t);
|
2017-09-16 04:10:14 +00:00
|
|
|
|
2017-09-16 07:01:03 +00:00
|
|
|
QSE_ASSERT (qse_log_getoption (log) == (QSE_LOG_INCLUDE_PID | QSE_LOG_HOST_IN_REMOTE_SYSLOG));
|
2017-09-16 04:10:14 +00:00
|
|
|
QSE_ASSERT (qse_log_gettarget (log, QSE_NULL) == (QSE_LOG_CONSOLE | QSE_LOG_FILE | QSE_LOG_SYSLOG | QSE_LOG_SYSLOG_REMOTE));
|
|
|
|
|
2017-09-18 02:46:54 +00:00
|
|
|
t1_sub001 (log);
|
|
|
|
|
2017-09-16 04:10:14 +00:00
|
|
|
for (i = 0; i < 10; i++)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (i == 4)
|
|
|
|
{
|
2019-11-09 00:32:34 +00:00
|
|
|
qse_log_target_data_t t2;
|
2017-09-16 04:10:14 +00:00
|
|
|
|
|
|
|
qse_log_gettarget (log, &t2);
|
2017-09-17 12:29:59 +00:00
|
|
|
qse_strtonwad (QSE_T("127.0.0.1:514"), &nwad);
|
2017-09-16 04:10:14 +00:00
|
|
|
qse_nwadtoskad (&nwad, &t2.syslog_remote);
|
|
|
|
qse_log_settarget (log, QSE_LOG_CONSOLE | QSE_LOG_FILE | QSE_LOG_SYSLOG_REMOTE, &t2);
|
|
|
|
|
|
|
|
qse_log_setoption (log, qse_log_getoption(log) | QSE_LOG_KEEP_FILE_OPEN);
|
|
|
|
|
2017-09-16 07:01:03 +00:00
|
|
|
QSE_ASSERT (qse_log_getoption (log) == (QSE_LOG_INCLUDE_PID | QSE_LOG_HOST_IN_REMOTE_SYSLOG | QSE_LOG_KEEP_FILE_OPEN));
|
2017-09-16 04:10:14 +00:00
|
|
|
QSE_ASSERT (qse_log_gettarget (log, QSE_NULL) == (QSE_LOG_CONSOLE | QSE_LOG_FILE | QSE_LOG_SYSLOG_REMOTE));
|
|
|
|
}
|
|
|
|
|
2018-01-28 04:51:22 +00:00
|
|
|
#if defined(QSE_HAVE_INT128_T)
|
|
|
|
QSE_LOG4 (log, QSE_T("test"), QSE_LOG_DEBUG, QSE_T("MSG %d %I128x %#0128I128b %l20d >>"), 10 * i , q, q, (long)45);
|
|
|
|
#elif defined(QSE_HAVE_INT64_T)
|
|
|
|
QSE_LOG4 (log, QSE_T("test"), QSE_LOG_DEBUG, QSE_T("MSG %d %I64x %#064I64b %l20d >>"), 10 * i , q, q, (long)45);
|
|
|
|
#else
|
|
|
|
QSE_LOG4 (log, QSE_T("test"), QSE_LOG_DEBUG, QSE_T("MSG %d %I32x %#032I32b %l20d >>"), 10 * i , q, q, (long)45);
|
|
|
|
#endif
|
2017-09-16 04:10:14 +00:00
|
|
|
}
|
|
|
|
|
2017-09-16 07:01:03 +00:00
|
|
|
|
|
|
|
#if defined(QSE_LOG)
|
|
|
|
QSE_LOG (log, QSE_T("var"), QSE_LOG_INFO, QSE_T("variadic QSE_LOG() supported - no argument"));
|
|
|
|
QSE_LOG (log, QSE_T("var"), QSE_LOG_ERROR, QSE_T("variadic QSE_LOG() supported %d %d"), 1, 2);
|
|
|
|
QSE_LOG (log, QSE_T("var"), QSE_LOG_PANIC, QSE_T("variadic QSE_LOG() supported %10s"), QSE_T("panic"));
|
|
|
|
#endif
|
2017-09-16 04:10:14 +00:00
|
|
|
qse_log_close (log);
|
|
|
|
}
|
|
|
|
|
|
|
|
int main (int argc, char* argv[])
|
|
|
|
{
|
|
|
|
t1 ();
|
|
|
|
return 0;
|
|
|
|
}
|