Simplify ConsoleMessage 54/41854/2
authorWonYoung Choi <wy80.choi@samsung.com>
Thu, 18 Jun 2015 10:55:58 +0000 (19:55 +0900)
committerWonYoung Choi <wy80.choi@samsung.com>
Fri, 19 Jun 2015 01:55:57 +0000 (10:55 +0900)
Change-Id: I5d4cea4901d1b69b65b0b9ccb93b68fc8a55ca1e

src/common/logger.h
src/runtime/web_application.cc
src/runtime/web_view_impl.cc

index 2bb5ee5..1ea5864 100755 (executable)
@@ -50,15 +50,24 @@ class LogMessageVodify {
 
 class LogMessage {
  public:
-  LogMessage(int severity, const char* file, const char* func, const int line)
-      : severity_(severity), file_(file), func_(func), line_(line) {}
+  LogMessage(int severity, const char* tag,
+             const char* file, const char* func, const int line)
+      : severity_(severity), tag_(tag), file_(file), func_(func), line_(line) {}
+  LogMessage(int severity, const char* tag)
+      : severity_(severity), tag_(tag), file_(NULL), func_(NULL), line_(0) {}
   ~LogMessage() {
-    __dlog_print(LOG_ID_MAIN, severity_, LOGGER_TAG,
-                 "%s: %s(%d) > %s", file_, func_, line_, stream_.str().c_str());
+    if (file_) {
+      __dlog_print(LOG_ID_MAIN, severity_, tag_,
+                   "%s: %s(%d) > %s",
+                   file_, func_, line_, stream_.str().c_str());
+    } else {
+      __dlog_print(LOG_ID_MAIN, severity_, tag_, "%s", stream_.str().c_str());
+    }
   }
   std::ostream& stream() { return stream_; }
  private:
   const int severity_;
+  const char* tag_;
   const char* file_;
   const char* func_;
   const int line_;
@@ -75,8 +84,12 @@ class LogMessage {
 
 #define LOGGER(severity)                                                      \
   wrt::utils::LogMessageVodify() &                                            \
-    wrt::utils::LogMessage(DLOG_ ## severity,                                 \
+    wrt::utils::LogMessage(DLOG_ ## severity, LOGGER_TAG,                     \
                            __MODULE__, __FUNCTION__, __LINE__).stream()
 
+#define LOGGER_RAW(level, tag)                                                \
+  wrt::utils::LogMessageVodify() &                                            \
+    wrt::utils::LogMessage(level, tag).stream()
+
 
 #endif  // WRT_COMMON_LOGGER_H_
index ef1f1e4..1612379 100755 (executable)
@@ -630,6 +630,7 @@ void WebApplication::OnLanguageChanged() {
 void WebApplication::OnConsoleMessage(const std::string& msg, int level) {
   static bool enabled = (getenv(kConsoleLogEnableKey) != NULL);
   enabled = true;
+
   if (debug_mode_ || enabled) {
     int dlog_level = DLOG_DEBUG;
     switch (level) {
@@ -643,7 +644,7 @@ void WebApplication::OnConsoleMessage(const std::string& msg, int level) {
           dlog_level = DLOG_DEBUG;
           break;
     }
-    LOG_(LOG_ID_MAIN, dlog_level, kConsoleMessageLogTag, "%s", msg.c_str());
+    LOGGER_RAW(dlog_level, kConsoleMessageLogTag) << msg;
   }
 }
 
index 3ae2068..583b37b 100755 (executable)
@@ -23,6 +23,7 @@
 
 #include "runtime/native_window.h"
 #include "common/logger.h"
+#include "common/file_utils.h"
 
 namespace wrt {
 
@@ -453,8 +454,8 @@ void WebViewImpl::InitConsoleMessageCallback() {
 
     std::stringstream buf;
     if (line_number) {
-        buf << ewk_console_message_source_get(msg) << ":";
-        buf << line_number << ":";
+        buf << utils::BaseName(ewk_console_message_source_get(msg)) << ":";
+        buf << line_number << ": ";
     }
     buf << ewk_console_message_text_get(msg);
     int level = ewk_console_message_level_get(msg);