#include <mstdlib/mstdlib_log.h>
#define STREAM_QUEUE_SIZE (1500*1000)
#define FILE_QUEUE_SIZE (1500*1000)
#define SYSLOG_QUEUE_SIZE (10*1000)
#define CRIT_FREQ (500)
#define NUM_MSGS (10*1000)
#ifdef FILE_DO_ARCHIVE
static const char *archive_cmd = "bzip2 -f";
static const char *archive_ext = ".bz2";
#else
static const char *archive_cmd = NULL;
static const char *archive_ext = NULL;
#endif
static const M_bool flush_on_destroy = M_TRUE;
typedef enum {
TAG_1 = 1 << 0,
TAG_2 = 1 << 1,
TAG_3 = 1 << 2,
CRIT_1 = 1 << 3,
CRIT_2 = 1 << 4,
CRIT_3 = 1 << 5
} tags_t;
static const char *tag_to_str(tags_t tag)
{
switch (tag) {
case TAG_1: return "tag 1";
case TAG_2: return "tag 2";
case TAG_3: return "tag 3";
case CRIT_1: return "CRITICAL 1";
case CRIT_2: return "CRITICAL 2";
case CRIT_3: return "CRITICAL 3";
}
return "unknown tag";
}
typedef struct {
const char *msg;
tags_t tag;
tags_t crit_tag;
} tdata_t;
static void set(tdata_t *td,
M_log_t *log,
const char *msg, tags_t tag, tags_t crit_tag)
{
td->log = log;
td->msg = msg;
td->tag = tag;
td->crit_tag = crit_tag;
}
static void prefix_cb(
M_buf_t *buf, M_uint64 tag,
void *prefix_thunk,
void *msg_thunk)
{
(void)prefix_thunk;
(void)msg_thunk;
M_bprintf(buf,
": [%s]\t", tag_to_str((tags_t)tag));
}
static void *test_thread(void *arg)
{
tdata_t *td = arg;
M_uint64 i;
M_uint64 crit;
crit = CRIT_FREQ;
for (i=0; i<NUM_MSGS; i++) {
tags_t tag;
if (crit >= CRIT_FREQ) {
tag = td->crit_tag;
crit = 1;
} else {
tag = td->tag;
++crit;
}
#ifdef ADD_LINE_END
"%s --\n %llu",
#else
"%s -- %llu",
#endif
td->msg, i);
}
}
return NULL;
}
int main(int argc, char *argv[])
{
#ifdef DO_MEMBUF
#endif
tdata_t data1, data2, data3;
(void)argc;
(void)argv;
} else {
}
res =
M_log_module_add_file(log,
"~/Tmp/logs/testing.log", 15, 150000, 0, FILE_QUEUE_SIZE, archive_cmd, archive_ext, &mod_file);
} else {
}
} else {
}
set(&data1, log, "data1", TAG_1, CRIT_1);
set(&data2, log, "data2", TAG_2, CRIT_2);
set(&data3, log, "data3", TAG_3, CRIT_3);
#ifdef DO_MEMBUF
} else {
}
#endif
#ifdef DO_MEMBUF
#endif
return EXIT_SUCCESS;
}
struct M_buf M_buf_t
Definition: m_buf.h:77
const char * M_buf_peek(const M_buf_t *buf)
size_t M_buf_len(const M_buf_t *buf)
void M_buf_cancel(M_buf_t *buf) M_FREE(1)
ssize_t M_fprintf(FILE *stream, const char *fmt,...)
size_t M_bprintf(M_buf_t *buf, const char *fmt,...)
struct M_fs_file M_fs_file_t
Definition: m_fs.h:132
@ M_FS_FILE_RW_NORMAL
Definition: m_fs.h:262
@ M_FS_FILE_MODE_OVERWRITE
Definition: m_fs.h:251
@ M_FS_FILE_MODE_WRITE
Definition: m_fs.h:248
void M_fs_file_close(M_fs_file_t *fd)
M_fs_error_t M_fs_file_open(M_fs_file_t **fd, const char *path, size_t buf_size, M_uint32 mode, const M_fs_perms_t *perms)
M_fs_error_t M_fs_file_write(M_fs_file_t *fd, const unsigned char *buf, size_t count, size_t *wrote_len, M_uint32 flags)
M_log_error_t M_log_set_time_format(M_log_t *log, const char *fmt)
M_log_error_t M_log_set_tag_name(M_log_t *log, M_uint64 tag, const char *name)
M_log_error_t M_log_module_set_accepted_tags(M_log_t *log, M_log_module_t *module, M_uint64 tags)
M_log_error_t M_log_module_set_prefix(M_log_t *log, M_log_module_t *module, M_log_prefix_cb prefix_cb, void *prefix_thunk, M_log_destroy_cb thunk_destroy_cb)
void M_log_suspend(M_log_t *log)
const char * M_log_err_to_str(M_log_error_t err)
void M_log_emergency(M_log_t *log, const char *msg)
void M_log_destroy_blocking(M_log_t *log, M_uint64 timeout_ms)
void M_log_resume(M_log_t *log, M_event_t *event)
struct M_log_module M_log_module_t
Definition: m_log.h:126
M_log_error_t
Definition: m_log.h:210
struct M_log M_log_t
Definition: m_log.h:122
M_log_error_t M_log_printf(M_log_t *log, M_uint64 tag, void *msg_thunk, const char *fmt,...)
M_log_t * M_log_create(M_log_line_end_mode_t mode, M_bool flush_on_destroy, M_event_t *event)
@ M_LOG_LINE_END_NATIVE
Definition: m_log.h:243
@ M_STREAM_STDOUT
Definition: m_log.h:251
@ M_LOG_SUCCESS
Definition: m_log.h:211
@ M_SYSLOG_WARNING
Definition: m_log.h:286
@ M_SYSLOG_CRIT
Definition: m_log.h:284
@ M_SYSLOG_FACILITY_LOCAL5
Definition: m_log.h:265
M_log_error_t M_log_module_add_file(M_log_t *log, const char *log_file_path, size_t num_to_keep, M_uint64 autorotate_size, M_uint64 autorotate_time_s, size_t max_queue_bytes, const char *archive_cmd, const char *archive_file_ext, M_log_module_t **out_mod)
M_log_error_t M_log_module_add_membuf(M_log_t *log, size_t buf_size, M_uint64 buf_time_s, M_log_expire_cb expire_cb, void *expire_thunk, M_log_module_t **out_mod)
M_log_error_t M_log_module_take_membuf(M_log_t *log, M_log_module_t *module, M_buf_t **out_buf)
M_log_error_t M_log_module_add_stream(M_log_t *log, M_stream_type_t type, size_t max_queue_bytes, M_log_module_t **out_mod)
M_log_error_t M_log_module_syslog_set_tag_priority(M_log_t *log, M_log_module_t *module, M_uint64 tags, M_syslog_priority_t priority)
M_log_error_t M_log_module_add_syslog(M_log_t *log, const char *product, M_syslog_facility_t facility, size_t max_queue_bytes, M_log_module_t **out_mod)
M_threadid_t M_thread_create(const M_thread_attr_t *attr, void *(*func)(void *), void *arg)
void M_thread_attr_destroy(M_thread_attr_t *attr)
M_thread_attr_t * M_thread_attr_create(void)
struct M_thread_attr M_thread_attr_t
Definition: m_thread.h:228
M_bool M_thread_join(M_threadid_t id, void **value_ptr)
void M_thread_sleep(M_uint64 usec)
void M_thread_attr_set_create_joinable(M_thread_attr_t *attr, M_bool val)
M_uintptr M_threadid_t
Definition: m_thread.h:223