From 1b25d3822a3794e7edfaeec14628b1f5c0b1089b Mon Sep 17 00:00:00 2001 From: haozi007 Date: Sat, 30 Jan 2021 14:30:55 +0800 Subject: [PATCH 1/2] support quiet of log config Signed-off-by: haozi007 --- tests/log_ut.cpp | 8 ++++---- third_party/log.c | 17 ++++++++--------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/tests/log_ut.cpp b/tests/log_ut.cpp index 3694160..8cf6599 100644 --- a/tests/log_ut.cpp +++ b/tests/log_ut.cpp @@ -40,18 +40,18 @@ TEST(log_testcases, test_isula_libutils_default_log_config) isula_libutils_default_log_config(name, &tconf); ASSERT_EQ(tconf.file, nullptr); - ASSERT_EQ(tconf.driver, nullptr); + EXPECT_STREQ(tconf.driver, ISULA_LOG_DRIVER_STDOUT); EXPECT_STREQ(name, tconf.name); - EXPECT_STREQ("FATAL", tconf.priority); + EXPECT_STREQ("DEBUG", tconf.priority); // not quiet configs check tconf.quiet = false; isula_libutils_default_log_config(name, &tconf); ASSERT_EQ(tconf.file, nullptr); - ASSERT_NE(tconf.driver, nullptr); + EXPECT_STREQ(tconf.driver, ISULA_LOG_DRIVER_STDOUT); EXPECT_STREQ(name, tconf.name); - EXPECT_STREQ(ISULA_LOG_DRIVER_STDOUT, tconf.driver); + EXPECT_STREQ("DEBUG", tconf.priority); } static void check_log(int fd, bool exist, bool subcheck, const char *target) diff --git a/third_party/log.c b/third_party/log.c index 83de005..2fcb014 100644 --- a/third_party/log.c +++ b/third_party/log.c @@ -79,11 +79,9 @@ void isula_libutils_default_log_config(const char *name, struct isula_libutils_l { log->name = name; log->file = NULL; - // use to disable log - log->priority = "FATAL"; - if (!log->quiet) { - log->driver = ISULA_LOG_DRIVER_STDOUT; - } + log->priority = "DEBUG"; + log->quiet = true; + log->driver = ISULA_LOG_DRIVER_STDOUT; } void isula_libutils_set_log_prefix(const char *prefix) @@ -103,9 +101,6 @@ void isula_libutils_free_log_prefix(void) /*---------------------------------------------------------------------------*/ static int log_append_stderr(const struct lxc_log_appender *appender, struct lxc_log_event *event) { - if (event->priority < LXC_LOG_LEVEL_ERROR) - return 0; - if (event->locinfo->file == NULL) { return 0; } @@ -410,6 +405,11 @@ int isula_libutils_log_enable(const struct isula_libutils_log_config *log) return 0; } + if (log->quiet) { + g_lxc_log_category_lxc.priority = LXC_LOG_LEVEL_FATAL; + return 0; + } + if (!choice_log_driver(log)) { COMMAND_ERROR("Invalid log config of driver"); return -1; @@ -422,7 +422,6 @@ int isula_libutils_log_enable(const struct isula_libutils_log_config *log) isula_libutils_set_log_prefix(log->prefix != NULL ? log->prefix : log->name); - return 0; } -- 2.25.1