morningman commented on code in PR #40347:
URL: https://github.com/apache/doris/pull/40347#discussion_r1743905527


##########
be/src/common/logconfig.cpp:
##########
@@ -49,21 +49,41 @@ static bool iequals(const std::string& a, const 
std::string& b) {
     return true;
 }
 
-void custom_prefix(std::ostream& s, const google::LogMessageInfo& l, void*) {
-    // Add prefix "RuntimeLogger ".
-    s << "RuntimeLogger ";
-    // Same as in fe.log
-    // The following is same as default log format. eg:
-    // I20240605 15:25:15.677153 1763151 wal_manager.cpp:481] msg...
+// if custom_date_time_format = false, same format as in be.log
+// The following is same as default log format. eg:
+// I20240605 15:25:15.677153 1763151 wal_manager.cpp:481] msg...
+template <bool add_runtime_logger_prefix = false, bool custom_date_time_format 
= false>
+void custom_prefix(std::ostream& s, const google::LogMessageInfo& l, void* 
arg) {
+    if constexpr (add_runtime_logger_prefix) {
+        // Add prefix "RuntimeLogger ".
+        s << "RuntimeLogger ";
+    }
     s << l.severity[0];
-    s << std::setw(4) << 1900 + l.time.year();
-    s << std::setw(2) << 1 + l.time.month();
-    s << std::setw(2) << l.time.day();
-    s << ' ';
-    s << std::setw(2) << l.time.hour() << ':';
-    s << std::setw(2) << l.time.min() << ':';
-    s << std::setw(2) << l.time.sec() << ".";
-    s << std::setw(6) << l.time.usec();
+
+    // Add a space if custom_date_time_format.
+    if constexpr (custom_date_time_format) {
+        s << ' ';

Review Comment:
   Why need a space here?



##########
be/src/common/logconfig.cpp:
##########
@@ -49,21 +49,41 @@ static bool iequals(const std::string& a, const 
std::string& b) {
     return true;
 }
 
-void custom_prefix(std::ostream& s, const google::LogMessageInfo& l, void*) {
-    // Add prefix "RuntimeLogger ".
-    s << "RuntimeLogger ";
-    // Same as in fe.log
-    // The following is same as default log format. eg:
-    // I20240605 15:25:15.677153 1763151 wal_manager.cpp:481] msg...
+// if custom_date_time_format = false, same format as in be.log
+// The following is same as default log format. eg:
+// I20240605 15:25:15.677153 1763151 wal_manager.cpp:481] msg...
+template <bool add_runtime_logger_prefix = false, bool custom_date_time_format 
= false>
+void custom_prefix(std::ostream& s, const google::LogMessageInfo& l, void* 
arg) {
+    if constexpr (add_runtime_logger_prefix) {
+        // Add prefix "RuntimeLogger ".
+        s << "RuntimeLogger ";
+    }
     s << l.severity[0];
-    s << std::setw(4) << 1900 + l.time.year();
-    s << std::setw(2) << 1 + l.time.month();
-    s << std::setw(2) << l.time.day();
-    s << ' ';
-    s << std::setw(2) << l.time.hour() << ':';
-    s << std::setw(2) << l.time.min() << ':';
-    s << std::setw(2) << l.time.sec() << ".";
-    s << std::setw(6) << l.time.usec();
+
+    // Add a space if custom_date_time_format.
+    if constexpr (custom_date_time_format) {
+        s << ' ';
+    }
+
+    std::tm tm_time = {};
+    tm_time.tm_year = l.time.year();
+    tm_time.tm_mon = l.time.month();
+    tm_time.tm_mday = l.time.day();
+    tm_time.tm_hour = l.time.hour();
+    tm_time.tm_min = l.time.min();
+    tm_time.tm_sec = l.time.sec();
+
+    if constexpr (custom_date_time_format) {
+        s << std::put_time(&tm_time, 
config::sys_log_custom_date_time_format.c_str());
+        if (!config::sys_log_custom_date_time_ms_format.empty()) {
+            s << fmt::format(config::sys_log_custom_date_time_ms_format,
+                             l.time.usec() / 1000); // 确保毫秒为三位数字

Review Comment:
   English comment



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


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

Reply via email to