From: Alexander Aksenov Date: Mon, 22 Oct 2018 18:22:42 +0000 (+0300) Subject: Logger: add dlog support X-Git-Tag: submit/tizen/20181205.102314~7^2~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c23bc193f53b06d8281dd49629b37d7035428c9e;p=sdk%2Ftools%2Fnetcoredbg.git Logger: add dlog support Signed-off-by: Alexander Aksenov --- diff --git a/packaging/netcoredbg.spec b/packaging/netcoredbg.spec index 4d2ea6c..9337597 100644 --- a/packaging/netcoredbg.spec +++ b/packaging/netcoredbg.spec @@ -23,6 +23,7 @@ BuildRequires: coreclr-devel BuildRequires: dotnet-build-tools BuildRequires: unzip BuildRequires: corefx-managed +BuildRequires: libdlog-devel Requires: coreclr # .NET Core Runtime diff --git a/src/debug/netcoredbg/CMakeLists.txt b/src/debug/netcoredbg/CMakeLists.txt index ad72280..55152e4 100644 --- a/src/debug/netcoredbg/CMakeLists.txt +++ b/src/debug/netcoredbg/CMakeLists.txt @@ -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}) diff --git a/src/debug/netcoredbg/logger.cpp b/src/debug/netcoredbg/logger.cpp index 65e6e3e..5928c2d 100644 --- a/src/debug/netcoredbg/logger.cpp +++ b/src/debug/netcoredbg/logger.cpp @@ -6,6 +6,33 @@ #include #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(level); break; + case DLOG_LOG: +#ifdef DEBUGGER_FOR_TIZEN + logger = std::make_shared(); + break; +#endif case NO_LOG: default: logger = std::make_shared(); diff --git a/src/debug/netcoredbg/logger.h b/src/debug/netcoredbg/logger.h index e0cb697..ac706b9 100644 --- a/src/debug/netcoredbg/logger.h +++ b/src/debug/netcoredbg/logger.h @@ -7,11 +7,14 @@ enum LogType { NO_LOG = 0, FILE_LOG, + DLOG_LOG, }; enum LogLevel { LOG_DEBUG = 0, LOG_INFO, + LOG_WARN, + LOG_ERROR, }; diff --git a/src/debug/netcoredbg/main.cpp b/src/debug/netcoredbg/main.cpp index 9614b76..98f5368 100644 --- a/src/debug/netcoredbg/main.cpp +++ b/src/debug/netcoredbg/main.cpp @@ -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[=] 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[=] 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;