43 lines
1003 B
C++
43 lines
1003 B
C++
#include <inttypes.h>
|
|
#include <gtest/gtest.h>
|
|
|
|
#define DI_LOG_ENABLE_FROM_DEBUG
|
|
#define DI_LOG_MODULE DI_LOG_MODULE_LIBDI_TEST
|
|
|
|
#include <di/log.h>
|
|
|
|
void log_writer_stdout(const struct di_log_msg *msg, void *private_data) {
|
|
(void)private_data;
|
|
|
|
printf("%s[%" PRIu64 "][%s]{%s:%s} %s%s\n",
|
|
di_log_decorate_begin(msg->loglevel),
|
|
msg->timestamp,
|
|
di_log_level_str(msg->loglevel),
|
|
di_log_component_str(msg->component),
|
|
di_log_module_str(msg->component, msg->module),
|
|
msg->msg,
|
|
di_log_decorate_end());
|
|
}
|
|
|
|
/**
|
|
* Try to initialize twice and check if NULL writer will not crash
|
|
*/
|
|
TEST(log, init_null) {
|
|
di_log_init(DI_LOG_LEVEL_DEBUG, NULL, NULL);
|
|
di_log_init(DI_LOG_LEVEL_DEBUG, NULL, NULL);
|
|
DI_LOG_INFO("test null writer");
|
|
}
|
|
|
|
/**
|
|
* Set writer
|
|
*/
|
|
TEST(log, DI_LOG) {
|
|
di_log_init(DI_LOG_LEVEL_DEBUG, log_writer_stdout, NULL);
|
|
|
|
DI_LOG_CRIT("crit");
|
|
DI_LOG_ERROR("error");
|
|
DI_LOG_WARN("warn");
|
|
DI_LOG_INFO("info");
|
|
DI_LOG_DEBUG("debug");
|
|
}
|