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

guangmingchen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/brpc.git


The following commit(s) were added to refs/heads/master by this push:
     new e0fe40e4 Opt log function name (#3017)
e0fe40e4 is described below

commit e0fe40e4e42fe27167771e678ee7760d20ea0d62
Author: Bright Chen <chenguangmin...@foxmail.com>
AuthorDate: Mon Jul 7 22:46:22 2025 +0800

    Opt log function name (#3017)
---
 src/butil/logging.cc | 24 ++++++++----------------
 src/butil/logging.h  |  4 ++--
 2 files changed, 10 insertions(+), 18 deletions(-)

diff --git a/src/butil/logging.cc b/src/butil/logging.cc
index 2f759f6a..e4964d0e 100644
--- a/src/butil/logging.cc
+++ b/src/butil/logging.cc
@@ -152,7 +152,10 @@ DEFINE_bool(log_hostname, false, "Add host after pid in 
each log so"
 
 DEFINE_bool(log_year, false, "Log year in datetime part in each log");
 
-DEFINE_bool(log_func_name, false, "Log function name in each log");
+DEFINE_bool(log_func_name, false, "[DEPRECATED]Log function name in each log. "
+                                  "Now DefaultLogSink logs function names by 
default. "
+                                  "Customized LogSink can also log function 
names through "
+                                  "corresponding OnLogMessage.");
 
 DEFINE_bool(async_log, false, "Use async log");
 
@@ -1381,14 +1384,8 @@ void LogStream::FlushWithoutReset() {
         DoublyBufferedLogSink::ScopedPtr ptr;
         if (DoublyBufferedLogSink::GetInstance()->Read(&ptr) == 0 &&
             (*ptr) != NULL) {
-            bool result = false;
-            if (FLAGS_log_func_name) {
-                result = (*ptr)->OnLogMessage(_severity, _file, _line,
-                                              _func, content());
-            } else {
-                result = (*ptr)->OnLogMessage(_severity, _file,
-                                              _line, content());
-            }
+            bool result = (*ptr)->OnLogMessage(
+                _severity, _file, _line, _func, content());
             if (result) {
                 goto FINISH_LOGGING;
             }
@@ -1408,13 +1405,8 @@ void LogStream::FlushWithoutReset() {
     }
 #endif
     if (!tried_default) {
-        if (FLAGS_log_func_name) {
-            DefaultLogSink::GetInstance()->OnLogMessage(
-                _severity, _file, _line, _func, content());
-        } else {
-            DefaultLogSink::GetInstance()->OnLogMessage(
-                _severity, _file, _line, content());
-        }
+        DefaultLogSink::GetInstance()->OnLogMessage(
+            _severity, _file, _line, _func, content());
     }
 
 FINISH_LOGGING:
diff --git a/src/butil/logging.h b/src/butil/logging.h
index 58e36918..d612e868 100644
--- a/src/butil/logging.h
+++ b/src/butil/logging.h
@@ -326,9 +326,9 @@ public:
     virtual bool OnLogMessage(int severity, const char* file, int line,
                               const butil::StringPiece& log_content) = 0;
     virtual bool OnLogMessage(int severity, const char* file,
-                              int line, const char* func,
+                              int line, const char* /*func*/,
                               const butil::StringPiece& log_content) {
-        return true;
+        return OnLogMessage(severity, file, line, log_content);
     }
 private:
     DISALLOW_COPY_AND_ASSIGN(LogSink);


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@brpc.apache.org
For additional commands, e-mail: dev-h...@brpc.apache.org

Reply via email to