This is an automated email from the ASF dual-hosted git repository.

wangdan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-pegasus.git


The following commit(s) were added to refs/heads/master by this push:
     new 0504f777a fix(logger): logs fail to be printed to stdout and the 
process is not terminated for fatal errors before logging is initialized (#1803)
0504f777a is described below

commit 0504f777a7451130e362112c29f580f76d6e42ea
Author: Dan Wang <[email protected]>
AuthorDate: Thu Dec 21 11:16:20 2023 +0800

    fix(logger): logs fail to be printed to stdout and the process is not 
terminated for fatal errors before logging is initialized (#1803)
    
    https://github.com/apache/incubator-pegasus/issues/1807
    
    Implement `dsn_log` interface for `screen_logger` in case that there is
    not any logging message being printed and the process is not terminated,
    while invalid values for the options loaded from configuration file are 
found,
    or some other errors occur that would make assertions fail.
---
 .../simple_kv/test/simple_kv.server.impl.cpp       |  5 +----
 src/utils/simple_logger.cpp                        | 25 ++++++++++++++++++++++
 src/utils/simple_logger.h                          |  4 +---
 3 files changed, 27 insertions(+), 7 deletions(-)

diff --git a/src/replica/storage/simple_kv/test/simple_kv.server.impl.cpp 
b/src/replica/storage/simple_kv/test/simple_kv.server.impl.cpp
index baf66a755..19db55f6a 100644
--- a/src/replica/storage/simple_kv/test/simple_kv.server.impl.cpp
+++ b/src/replica/storage/simple_kv/test/simple_kv.server.impl.cpp
@@ -37,12 +37,12 @@
 
 #include "aio/aio_task.h"
 #include "aio/file_io.h"
+#include "common/replication.codes.h"
 #include "consensus_types.h"
 #include "rocksdb/env.h"
 #include "rocksdb/slice.h"
 #include "rocksdb/status.h"
 #include "runtime/serverlet.h"
-#include "runtime/task/task_code.h"
 #include "simple_kv_types.h"
 #include "utils/autoref_ptr.h"
 #include "utils/binary_reader.h"
@@ -50,7 +50,6 @@
 #include "utils/env.h"
 #include "utils/filesystem.h"
 #include "utils/fmt_logging.h"
-#include "utils/threadpool_code.h"
 #include "utils/utils.h"
 
 // TODO(yingchun): most of the code are the same as
@@ -68,8 +67,6 @@ namespace dsn {
 namespace replication {
 namespace test {
 
-DEFINE_TASK_CODE(LPC_AIO_IMMEDIATE_CALLBACK, TASK_PRIORITY_COMMON, 
dsn::THREAD_POOL_DEFAULT)
-
 bool simple_kv_service_impl::s_simple_kv_open_fail = false;
 bool simple_kv_service_impl::s_simple_kv_close_fail = false;
 bool simple_kv_service_impl::s_simple_kv_get_checkpoint_fail = false;
diff --git a/src/utils/simple_logger.cpp b/src/utils/simple_logger.cpp
index afcaf2031..a555fd12f 100644
--- a/src/utils/simple_logger.cpp
+++ b/src/utils/simple_logger.cpp
@@ -138,6 +138,31 @@ void screen_logger::dsn_logv(const char *file,
     vprintf(fmt, args);
     printf("\n");
 
+    if (log_level >= LOG_LEVEL_ERROR) {
+        ::fflush(stdout);
+    }
+
+    process_fatal_log(log_level);
+}
+
+void screen_logger::dsn_log(const char *file,
+                            const char *function,
+                            const int line,
+                            dsn_log_level_t log_level,
+                            const char *str)
+{
+    utils::auto_lock<::dsn::utils::ex_lock_nr> l(_lock);
+
+    print_header(stdout, log_level);
+    if (!_short_header) {
+        printf("%s:%d:%s(): ", file, line, function);
+    }
+    printf("%s\n", str);
+
+    if (log_level >= LOG_LEVEL_ERROR) {
+        ::fflush(stdout);
+    }
+
     process_fatal_log(log_level);
 }
 
diff --git a/src/utils/simple_logger.h b/src/utils/simple_logger.h
index 71535b26f..9e502ac44 100644
--- a/src/utils/simple_logger.h
+++ b/src/utils/simple_logger.h
@@ -57,9 +57,7 @@ public:
                  const char *function,
                  const int line,
                  dsn_log_level_t log_level,
-                 const char *str) override
-    {
-    }
+                 const char *str) override;
 
     virtual void flush();
 


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to