some refactoring of qse_log_t related functions
This commit is contained in:
parent
3130a85700
commit
4a1e4858a7
@ -184,19 +184,23 @@ public:
|
||||
void setLogMask (int mask) { this->_log.mask = mask; }
|
||||
int getLogMask () const { return this->_log.mask; }
|
||||
|
||||
/*
|
||||
void setLogTarget (int flags, const qse_log_target_t& target)
|
||||
{
|
||||
if (this->_log.logger) qse_log_settarget (this->_log.logger, flags, &target);
|
||||
}
|
||||
|
||||
void setLogOption (int oflags)
|
||||
{
|
||||
qse_log_setoption (&this->_log.logger, oflags);
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
void
|
||||
|
||||
void setLogTarget (int target_flags, const qse_log_target_data_t& target)
|
||||
{
|
||||
qse_log_settarget (this->_log.logger, target_flags, &target);
|
||||
}
|
||||
|
||||
int getLogTarget (qse_log_target_data_t& target)
|
||||
{
|
||||
return qse_log_gettarget(this->_log.logger, &target);
|
||||
}
|
||||
|
||||
void logfmt (int mask, const qse_char_t* fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
@ -46,32 +46,35 @@
|
||||
|
||||
|
||||
/* priority */
|
||||
#define QSE_LOG_PANIC (1 << 0)
|
||||
#define QSE_LOG_ALERT (1 << 1)
|
||||
#define QSE_LOG_CRITICAL (1 << 2)
|
||||
#define QSE_LOG_ERROR (1 << 3)
|
||||
#define QSE_LOG_WARNING (1 << 4)
|
||||
#define QSE_LOG_NOTICE (1 << 5)
|
||||
#define QSE_LOG_INFO (1 << 6)
|
||||
#define QSE_LOG_DEBUG (1 << 7)
|
||||
#define QSE_LOG_ALL_PRIORITIES \
|
||||
(QSE_LOG_PANIC | QSE_LOG_ALERT | QSE_LOG_CRITICAL | \
|
||||
QSE_LOG_ERROR | QSE_LOG_WARNING | QSE_LOG_NOTICE | \
|
||||
QSE_LOG_INFO | QSE_LOG_DEBUG)
|
||||
|
||||
/* options */
|
||||
#define QSE_LOG_KEEP_FILE_OPEN (1 << 13)
|
||||
#define QSE_LOG_MASKED_PRIORITY (1 << 14)
|
||||
#define QSE_LOG_INCLUDE_PID (1 << 15)
|
||||
#define QSE_LOG_HOST_IN_REMOTE_SYSLOG (1 << 16)
|
||||
|
||||
/* target */
|
||||
#define QSE_LOG_CONSOLE (1 << 20)
|
||||
#define QSE_LOG_FILE (1 << 21)
|
||||
#define QSE_LOG_SYSLOG (1 << 22)
|
||||
#define QSE_LOG_SYSLOG_REMOTE (1 << 23)
|
||||
enum qse_log_priority_flag_t /* bit 0 to 7. potentially to be extended beyond */
|
||||
{
|
||||
QSE_LOG_PANIC = (1 << 0),
|
||||
QSE_LOG_ALERT = (1 << 1),
|
||||
QSE_LOG_CRITICAL = (1 << 2),
|
||||
QSE_LOG_ERROR = (1 << 3),
|
||||
QSE_LOG_WARNING = (1 << 4),
|
||||
QSE_LOG_NOTICE = (1 << 5),
|
||||
QSE_LOG_INFO = (1 << 6),
|
||||
QSE_LOG_DEBUG = (1 << 7),
|
||||
QSE_LOG_ALL_PRIORITIES = (QSE_LOG_PANIC | QSE_LOG_ALERT | QSE_LOG_CRITICAL | QSE_LOG_ERROR | QSE_LOG_WARNING | QSE_LOG_NOTICE | QSE_LOG_INFO | QSE_LOG_DEBUG)
|
||||
};
|
||||
|
||||
enum qse_log_option_flag_t /* bit 12 to 19 */
|
||||
{
|
||||
QSE_LOG_KEEP_FILE_OPEN = (1 << 12),
|
||||
QSE_LOG_MASKED_PRIORITY = (1 << 13),
|
||||
QSE_LOG_INCLUDE_PID = (1 << 14),
|
||||
QSE_LOG_HOST_IN_REMOTE_SYSLOG = (1 << 15),
|
||||
};
|
||||
|
||||
enum qse_log_target_flag_t /* bit 20 to 31 */
|
||||
{
|
||||
QSE_LOG_CONSOLE = (1 << 20),
|
||||
QSE_LOG_FILE = (1 << 21),
|
||||
QSE_LOG_SYSLOG = (1 << 22),
|
||||
QSE_LOG_SYSLOG_REMOTE = (1 << 23)
|
||||
};
|
||||
|
||||
/* facility */
|
||||
enum qse_log_facility_t
|
||||
@ -247,23 +250,23 @@ struct qse_log_t
|
||||
};
|
||||
|
||||
|
||||
struct qse_log_target_t
|
||||
struct qse_log_target_data_t
|
||||
{
|
||||
const qse_char_t* file;
|
||||
qse_skad_t syslog_remote;
|
||||
};
|
||||
typedef struct qse_log_target_t qse_log_target_t;
|
||||
typedef struct qse_log_target_data_t qse_log_target_data_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
QSE_EXPORT qse_log_t* qse_log_open (
|
||||
qse_mmgr_t* mmgr,
|
||||
qse_size_t xtnsize,
|
||||
const qse_char_t* ident,
|
||||
int potflags, /* priority + option + target bits */
|
||||
const qse_log_target_t* target
|
||||
qse_mmgr_t* mmgr,
|
||||
qse_size_t xtnsize,
|
||||
const qse_char_t* ident,
|
||||
int potflags, /* priority + option + target bits */
|
||||
const qse_log_target_data_t* target_data
|
||||
);
|
||||
|
||||
QSE_EXPORT void qse_log_close (
|
||||
@ -275,7 +278,7 @@ QSE_EXPORT int qse_log_init (
|
||||
qse_mmgr_t* mmgr,
|
||||
const qse_char_t* ident,
|
||||
int potflags,
|
||||
const qse_log_target_t* target
|
||||
const qse_log_target_data_t* target_data
|
||||
);
|
||||
|
||||
QSE_EXPORT void qse_log_fini (
|
||||
@ -314,17 +317,17 @@ QSE_EXPORT void qse_log_setidentwithwcs (
|
||||
* \return 0 on success, -1 on failure
|
||||
*/
|
||||
QSE_EXPORT int qse_log_settarget (
|
||||
qse_log_t* log,
|
||||
int flags,
|
||||
const qse_log_target_t* target
|
||||
qse_log_t* log,
|
||||
int target_flags,
|
||||
const qse_log_target_data_t* target_data
|
||||
);
|
||||
|
||||
/**
|
||||
* \return an integer bitwise-ORed of the target bits.
|
||||
* \return target flags which is an integer bitwise-ORed of the target bits.
|
||||
*/
|
||||
QSE_EXPORT int qse_log_gettarget (
|
||||
qse_log_t* log,
|
||||
qse_log_target_t* target
|
||||
qse_log_t* log,
|
||||
qse_log_target_data_t* target_data
|
||||
);
|
||||
|
||||
QSE_EXPORT void qse_log_setoption (
|
||||
|
@ -198,14 +198,14 @@ static QSE_INLINE int get_active_priority_bits (int flags)
|
||||
return priority_bits;
|
||||
}
|
||||
|
||||
qse_log_t* qse_log_open (qse_mmgr_t* mmgr, qse_size_t xtnsize, const qse_char_t* ident, int potflags, const qse_log_target_t* target)
|
||||
qse_log_t* qse_log_open (qse_mmgr_t* mmgr, qse_size_t xtnsize, const qse_char_t* ident, int potflags, const qse_log_target_data_t* target_data)
|
||||
{
|
||||
qse_log_t* log;
|
||||
|
||||
log = (qse_log_t*) QSE_MMGR_ALLOC (mmgr, QSE_SIZEOF(qse_log_t) + xtnsize);
|
||||
if (log)
|
||||
{
|
||||
if (qse_log_init(log, mmgr, ident, potflags, target) <= -1)
|
||||
if (qse_log_init(log, mmgr, ident, potflags, target_data) <= -1)
|
||||
{
|
||||
QSE_MMGR_FREE (mmgr, log);
|
||||
return QSE_NULL;
|
||||
@ -222,7 +222,7 @@ void qse_log_close (qse_log_t* log)
|
||||
QSE_MMGR_FREE (log->mmgr, log);
|
||||
}
|
||||
|
||||
int qse_log_init (qse_log_t* log, qse_mmgr_t* mmgr, const qse_char_t* ident, int potflags, const qse_log_target_t* target)
|
||||
int qse_log_init (qse_log_t* log, qse_mmgr_t* mmgr, const qse_char_t* ident, int potflags, const qse_log_target_data_t* target_data)
|
||||
{
|
||||
QSE_MEMSET (log, 0, QSE_SIZEOF(*log));
|
||||
log->mmgr = mmgr;
|
||||
@ -231,16 +231,16 @@ int qse_log_init (qse_log_t* log, qse_mmgr_t* mmgr, const qse_char_t* ident, int
|
||||
log->t.syslog_remote.sock = -1;
|
||||
|
||||
if (potflags & QSE_LOG_FILE) log->flags |= QSE_LOG_FILE;
|
||||
if (target && target->file)
|
||||
if (target_data && target_data->file)
|
||||
{
|
||||
if (qse_strlen(target->file) >= QSE_COUNTOF(log->t.file.pathbuf))
|
||||
if (qse_strlen(target_data->file) >= QSE_COUNTOF(log->t.file.pathbuf))
|
||||
{
|
||||
log->t.file.path = qse_strdup(target->file, log->mmgr);
|
||||
log->t.file.path = qse_strdup(target_data->file, log->mmgr);
|
||||
if (!log->t.file.path) return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
qse_strxcpy (log->t.file.pathbuf, QSE_COUNTOF(log->t.file.pathbuf), target->file);
|
||||
qse_strxcpy (log->t.file.pathbuf, QSE_COUNTOF(log->t.file.pathbuf), target_data->file);
|
||||
log->t.file.path = log->t.file.pathbuf;
|
||||
}
|
||||
}
|
||||
@ -249,7 +249,7 @@ int qse_log_init (qse_log_t* log, qse_mmgr_t* mmgr, const qse_char_t* ident, int
|
||||
if (potflags & QSE_LOG_SYSLOG) log->flags |= QSE_LOG_SYSLOG;
|
||||
|
||||
if (potflags & QSE_LOG_SYSLOG_REMOTE) log->flags |= QSE_LOG_SYSLOG_REMOTE;
|
||||
if (target && qse_skadfamily(&target->syslog_remote) >= 0) log->t.syslog_remote.addr = target->syslog_remote;
|
||||
if (target_data && qse_skadfamily(&target_data->syslog_remote) >= 0) log->t.syslog_remote.addr = target_data->syslog_remote;
|
||||
|
||||
if (ident) qse_strxcpy (log->ident, QSE_COUNTOF(log->ident), ident);
|
||||
if (qse_mtx_init(&log->mtx, mmgr) <= -1)
|
||||
@ -370,13 +370,13 @@ void qse_log_setidentwithwcs (qse_log_t* log, const qse_wchar_t* ident)
|
||||
}
|
||||
|
||||
|
||||
int qse_log_settarget (qse_log_t* log, int flags, const qse_log_target_t* target)
|
||||
int qse_log_settarget (qse_log_t* log, int flags, const qse_log_target_data_t* target_data)
|
||||
{
|
||||
qse_char_t* target_file = QSE_NULL;
|
||||
if (target->file && qse_strlen(target->file) >= QSE_COUNTOF(log->t.file.pathbuf))
|
||||
qse_char_t* target_data_file = QSE_NULL;
|
||||
if (target_data->file && qse_strlen(target_data->file) >= QSE_COUNTOF(log->t.file.pathbuf))
|
||||
{
|
||||
target_file = qse_strdup (target->file, log->mmgr);
|
||||
if (!target_file) return -1;
|
||||
target_data_file = qse_strdup (target_data->file, log->mmgr);
|
||||
if (!target_data_file) return -1;
|
||||
}
|
||||
|
||||
if (log->t.syslog_remote.sock >= 0)
|
||||
@ -406,20 +406,20 @@ int qse_log_settarget (qse_log_t* log, int flags, const qse_log_target_t* target
|
||||
log->flags &= (QSE_LOG_MASK_PRIORITY | QSE_LOG_MASK_OPTION); /* preserve the priority and the options */
|
||||
if (flags & QSE_LOG_FILE) log->flags |= QSE_LOG_FILE;
|
||||
|
||||
/* If you just want to set the target file path without enable QSE_LOG_FILE,
|
||||
* just set target->file without QSE_LOG_FILE in the flags.
|
||||
* later, you can call this function with QSE_LOG_FILE set but with target->file or QSE_NULL */
|
||||
if (target && target->file)
|
||||
/* If you just want to set the target_data file path without enable QSE_LOG_FILE,
|
||||
* just set target_data->file without QSE_LOG_FILE in the flags.
|
||||
* later, you can call this function with QSE_LOG_FILE set but with target_data->file or QSE_NULL */
|
||||
if (target_data && target_data->file)
|
||||
{
|
||||
if (log->t.file.path && log->t.file.path != log->t.file.pathbuf) QSE_MMGR_FREE (log->mmgr, log->t.file.path);
|
||||
|
||||
if (target_file)
|
||||
if (target_data_file)
|
||||
{
|
||||
log->t.file.path = target_file;
|
||||
log->t.file.path = target_data_file;
|
||||
}
|
||||
else
|
||||
{
|
||||
qse_strxcpy (log->t.file.pathbuf, QSE_COUNTOF(log->t.file.pathbuf), target->file);
|
||||
qse_strxcpy (log->t.file.pathbuf, QSE_COUNTOF(log->t.file.pathbuf), target_data->file);
|
||||
log->t.file.path = log->t.file.pathbuf;
|
||||
}
|
||||
}
|
||||
@ -428,17 +428,17 @@ int qse_log_settarget (qse_log_t* log, int flags, const qse_log_target_t* target
|
||||
if (flags & QSE_LOG_SYSLOG) log->flags |= QSE_LOG_SYSLOG;
|
||||
|
||||
if (flags & QSE_LOG_SYSLOG_REMOTE) log->flags |= QSE_LOG_SYSLOG_REMOTE;
|
||||
if (target && qse_skadfamily(&target->syslog_remote) >= 0) log->t.syslog_remote.addr = target->syslog_remote;
|
||||
if (target_data && qse_skadfamily(&target_data->syslog_remote) >= 0) log->t.syslog_remote.addr = target_data->syslog_remote;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int qse_log_gettarget (qse_log_t* log, qse_log_target_t* target)
|
||||
int qse_log_gettarget (qse_log_t* log, qse_log_target_data_t* target_data)
|
||||
{
|
||||
if (target)
|
||||
if (target_data)
|
||||
{
|
||||
target->file = log->t.file.path;
|
||||
target->syslog_remote = log->t.syslog_remote.addr;
|
||||
target_data->file = log->t.file.path;
|
||||
target_data->syslog_remote = log->t.syslog_remote.addr;
|
||||
}
|
||||
return log->flags & QSE_LOG_MASK_TARGET;
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include <qse/cmn/test.h>
|
||||
#include <qse/cmn/mem.h>
|
||||
#include <qse/cmn/str.h>
|
||||
#include <qse/cmn/mbwc.h>
|
||||
#include <qse/si/sio.h>
|
||||
|
||||
#include <locale.h>
|
||||
@ -412,13 +413,13 @@ static int test18 (void)
|
||||
}
|
||||
|
||||
qse_str_ncat (s1, QSE_T("["), 1);
|
||||
qse_str_ncatwcs (s1, QSE_WT("hello"), 5);
|
||||
qse_str_ncatmbs (s1, QSE_MT("world"), 5);
|
||||
qse_str_ncatwcs (s1, QSE_WT("hello"), 5, qse_findcmgrbyid(QSE_CMGR_UTF8));
|
||||
qse_str_ncatmbs (s1, QSE_MT("world"), 5, qse_findcmgrbyid(QSE_CMGR_UTF8));
|
||||
qse_str_ncat (s1, QSE_T("]"), 1);
|
||||
|
||||
QSE_TESASSERT1 (QSE_STR_LEN(s1) == 12, QSE_T("wrong length of dynamic string"));
|
||||
|
||||
qse_str_ncatmbs (s1, QSE_MT("\xEB\xAC\xB4\xEB\xAC\xB4\xEB\xAC\xB4"), 9);
|
||||
qse_str_ncatmbs (s1, QSE_MT("\xEB\xAC\xB4\xEB\xAC\xB4\xEB\xAC\xB4"), 9, qse_findcmgrbyid(QSE_CMGR_UTF8));
|
||||
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
QSE_TESASSERT1 (QSE_STR_LEN(s1) == 21, QSE_T("wrong length of dynamic string"));
|
||||
@ -426,7 +427,7 @@ static int test18 (void)
|
||||
QSE_TESASSERT1 (QSE_STR_LEN(s1) == 15, QSE_T("wrong length of dynamic string"));
|
||||
#endif
|
||||
|
||||
qse_str_ncatwcs (s1, QSE_WT("날아올라라"), 5);
|
||||
qse_str_ncatwcs (s1, QSE_WT("날아올라라"), 5, qse_findcmgrbyid(QSE_CMGR_UTF8));
|
||||
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
QSE_TESASSERT1 (QSE_STR_LEN(s1) == 36, QSE_T("wrong length of dynamic string"));
|
||||
|
@ -47,7 +47,7 @@ static void t1_sub001 (qse_log_t* log)
|
||||
static void t1 (void)
|
||||
{
|
||||
qse_log_t* log;
|
||||
qse_log_target_t t;
|
||||
qse_log_target_data_t t;
|
||||
#if defined(QSE_HAVE_INT128_T)
|
||||
qse_int128_t q = 0x1234567890;
|
||||
#elif defined(QSE_HAVE_INT64_T)
|
||||
@ -79,7 +79,7 @@ static void t1 (void)
|
||||
|
||||
if (i == 4)
|
||||
{
|
||||
qse_log_target_t t2;
|
||||
qse_log_target_data_t t2;
|
||||
|
||||
qse_log_gettarget (log, &t2);
|
||||
qse_strtonwad (QSE_T("127.0.0.1:514"), &nwad);
|
||||
|
@ -86,6 +86,10 @@ public:
|
||||
signals.set (SIGUSR2);
|
||||
if (this->guardProcess(signals) > 0)
|
||||
{
|
||||
int target_flags;
|
||||
qse_log_target_data_t target_data;
|
||||
|
||||
this->setLogTarget (target_flags, target_data);
|
||||
this->setLogMask (MyApp::LOG_ALL_LEVELS | MyApp::LOG_ALL_TYPES);
|
||||
|
||||
QSE_APP_LOG0 (this, MyApp::LOG_INFO | MyApp::LOG_TYPE_0, QSE_T("Stareting server\n"));
|
||||
|
Loading…
Reference in New Issue
Block a user