From 56f04da5fba089eac91c58044aca4168c38e8080 Mon Sep 17 00:00:00 2001 From: "Eunki, Hong" Date: Thu, 4 Jul 2024 19:16:18 +0900 Subject: [PATCH] [Tizen] Make Log::LogMessage print to stderr / stdout if log function not installed Until now, we just ignore the messages when we use Dali::Integration::Log::LogMessage(Something like, DALI_LOG_ERROR macro) when we don't install log function. The log function exist per each threads. But it is difficult to debug something at worker thread jobs what DALi cannot controled. (Like GC thread for dotnet Application) For more general and each debugging, let we print 'something' even if log function is not installed, like stderr. For now, Tizen platform re-open the stderr / stdout as dlog. and Linux-friendly + Windows support to print logs into stderr, stdout file. Change-Id: Iaf6a49d8aa9f53108b4c83bbdb18df406e3b57fa Signed-off-by: Eunki, Hong --- dali/integration-api/debug.cpp | 56 +++++++++++++++++++++++++++++++++++------- dali/integration-api/debug.h | 3 ++- 2 files changed, 49 insertions(+), 10 deletions(-) diff --git a/dali/integration-api/debug.cpp b/dali/integration-api/debug.cpp index dab8585..7647c22 100644 --- a/dali/integration-api/debug.cpp +++ b/dali/integration-api/debug.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Samsung Electronics Co., Ltd. + * Copyright (c) 2024 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -37,6 +37,39 @@ namespace Integration { namespace Log { +namespace +{ +void FormatPrintToStandardOutput(DebugPriority priority, const char* format, va_list args) +{ + if(format != nullptr) + { + char* buffer = nullptr; + int bufferLength = vasprintf(&buffer, format, args); // Development note : bufferLength doesn't include null-terminated character. + + if(bufferLength >= 0) // No error + { + // TODO : We need to consider thread-safety way to print something. + switch(priority) + { + case DebugPriority::DEBUG: + case DebugPriority::INFO: + { + fprintf(stdout, "%.*s", bufferLength, buffer); + break; + } + case DebugPriority::WARNING: + case DebugPriority::ERROR: + default: + { + fprintf(stderr, "%.*s", bufferLength, buffer); + break; + } + } + free(buffer); + } + } +} +} // namespace thread_local LogFunction gthreadLocalLogFunction = nullptr; /* Forward declarations */ @@ -45,17 +78,22 @@ std::string ArgListToString(const char* format, va_list args); void LogMessage(DebugPriority priority, const char* format, ...) { - if(!gthreadLocalLogFunction) + if(DALI_UNLIKELY(!gthreadLocalLogFunction)) { - return; + va_list arg; + va_start(arg, format); + FormatPrintToStandardOutput(priority, format, arg); + va_end(arg); } + else + { + va_list arg; + va_start(arg, format); + std::string message = ArgListToString(format, arg); + va_end(arg); - va_list arg; - va_start(arg, format); - std::string message = ArgListToString(format, arg); - va_end(arg); - - gthreadLocalLogFunction(priority, message); + gthreadLocalLogFunction(priority, message); + } } void InstallLogFunction(const LogFunction& logFunction) diff --git a/dali/integration-api/debug.h b/dali/integration-api/debug.h index 38a0ff0..5d81258 100644 --- a/dali/integration-api/debug.h +++ b/dali/integration-api/debug.h @@ -2,7 +2,7 @@ #define DALI_INTEGRATION_DEBUG_H /* - * Copyright (c) 2023 Samsung Electronics Co., Ltd. + * Copyright (c) 2024 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -124,6 +124,7 @@ using LogFunction = void (*)(DebugPriority, std::string&); * A log function has to be installed for every thread that wants to use logging. * This should be done by the adaptor. * The log function can be different for each thread. + * If a log function is not installed, the log message will be print at stderr. * @param logFunction the log function to install * @param logOpts the log options to save in thread */ -- 2.7.4