Logger: add dlog support
authorAlexander Aksenov <a.aksenov@samsung.com>
Mon, 22 Oct 2018 18:22:42 +0000 (21:22 +0300)
committerAlexander Aksenov <a.aksenov@samsung.com>
Tue, 30 Oct 2018 09:40:49 +0000 (12:40 +0300)
Signed-off-by: Alexander Aksenov <a.aksenov@samsung.com>
packaging/netcoredbg.spec
src/debug/netcoredbg/CMakeLists.txt
src/debug/netcoredbg/logger.cpp
src/debug/netcoredbg/logger.h
src/debug/netcoredbg/main.cpp

index 4d2ea6c..9337597 100644 (file)
@@ -23,6 +23,7 @@ BuildRequires: coreclr-devel
 BuildRequires: dotnet-build-tools
 BuildRequires: unzip
 BuildRequires: corefx-managed
+BuildRequires: libdlog-devel
 Requires: coreclr
 
 # .NET Core Runtime
index ad72280..55152e4 100644 (file)
@@ -59,6 +59,11 @@ else()
     target_link_libraries(netcoredbg corguids dl pthread)
 endif()
 
+if (CLR_CMAKE_TARGET_TIZEN_LINUX)
+    add_definitions(-DDEBUGGER_FOR_TIZEN)
+    target_link_libraries(netcoredbg dlog)
+endif (CLR_CMAKE_TARGET_TIZEN_LINUX)
+
 install(TARGETS netcoredbg DESTINATION ${CMAKE_INSTALL_PREFIX})
 if (DBGSHIM_LOCATION)
     install(FILES ${DBGSHIM_LOCATION} DESTINATION ${CMAKE_INSTALL_PREFIX})
index 65e6e3e..5928c2d 100644 (file)
@@ -6,6 +6,33 @@
 #include <chrono>
 #include "logger.h"
 
+#ifdef DEBUGGER_FOR_TIZEN
+#include "dlog/dlog.h"
+
+
+class DlogLogger : public LoggerImpl
+{
+    const std::string tag = "NETCOREDBG";
+
+    public:
+        DlogLogger() {}
+        ~DlogLogger() override {}
+        void log(LogLevel level, const std::string& msg) override;
+};
+
+void DlogLogger::log(LogLevel level, const std::string& msg)
+{
+    // Use LOG_DEBUG wisely!
+    if (level == LOG_DEBUG)
+        dlog_print(DLOG_DEBUG, tag.c_str(), "%s", msg.c_str());
+    else if (level == LOG_INFO)
+        dlog_print(DLOG_INFO, tag.c_str(), "%s", msg.c_str());
+    else if (level == LOG_WARN)
+        dlog_print(DLOG_WARN, tag.c_str(), "%s", msg.c_str());
+    else if (level == LOG_ERROR)
+        dlog_print(DLOG_ERROR, tag.c_str(), "%s", msg.c_str());
+}
+#endif
 
 
 
@@ -76,6 +103,11 @@ void Logger::setLogging(LogType type, LogLevel level)
     case FILE_LOG:
         logger = std::make_shared<FileLogger>(level);
         break;
+    case DLOG_LOG:
+#ifdef DEBUGGER_FOR_TIZEN
+        logger = std::make_shared<DlogLogger>();
+        break;
+#endif
     case NO_LOG:
     default:
         logger = std::make_shared<NoLogger>();
index e0cb697..ac706b9 100644 (file)
@@ -7,11 +7,14 @@
 enum LogType {
     NO_LOG = 0,
     FILE_LOG,
+    DLOG_LOG,
 };
 
 enum LogLevel {
     LOG_DEBUG = 0,
     LOG_INFO,
+    LOG_WARN,
+    LOG_ERROR,
 };
 
 
index 9614b76..98f5368 100644 (file)
@@ -29,10 +29,16 @@ static void print_help()
         "--server[=port_num]                   Start the debugger listening for requests on the\n"
         "                                      specified TCP/IP port instead of stdin/out. If port is not specified\n"
         "                                      TCP %i will be used.\n"
+        #ifdef DEBUGGER_FOR_TIZEN
+        "--log[=<debug>]                       Enable logging to dlog. Supported\n"
+        "                                      two log levels: info and debug. Info contains info, warn and error\n"
+        "                                      messages, debug the same and debug messages in addition. Info level\n"
+        "                                      is the default one. Overwrites other log types\n"
+        #endif
         "--log-file[=<debug>]                  Enable logging to file which is created in 'current'. Supported\n"
         "                                      two log levels: info and debug. Info contains info, warn and error\n"
         "                                      messages, debug the same and debug messages in addition. Info level\n"
-        "                                      is the default one.\n",
+        "                                      is the default one. Overwrites other log types\n",
         (int)DEFAULT_SERVER_PORT
     );
 }
@@ -101,6 +107,22 @@ int main(int argc, char *argv[])
             print_help();
             return EXIT_SUCCESS;
         }
+#ifdef DEBUGGER_FOR_TIZEN
+        else if (strcmp(argv[i], "--log") == 0)
+        {
+            logType = DLOG_LOG;
+        }
+        else if (strstr(argv[i], "--log=") == argv[i])
+        {
+            const std::string &debug = "debug";
+
+            logType = DLOG_LOG;
+            if (std::string(argv[i] + strlen("--log=")) == debug)
+                logLevel = LOG_DEBUG;
+            else
+                logLevel = LOG_INFO;
+        }
+#endif
         else if (strcmp(argv[i], "--log-file") == 0)
         {
             logType = FILE_LOG;
@@ -158,7 +180,7 @@ int main(int argc, char *argv[])
     }
 
     Logger::setLogging(logType, logLevel);
-    Logger::log("Start logging to file");
+    Logger::log("Start logging. Level %d", logLevel);
 
     ManagedDebugger debugger;
     std::unique_ptr<Protocol> protocol;