diff --git a/deps/node/src/lwnode/aul-event-receiver.cc b/deps/node/src/lwnode/aul-event-receiver.cc index 89b76ab68a..97f8e031b4 100644 --- a/deps/node/src/lwnode/aul-event-receiver.cc +++ b/deps/node/src/lwnode/aul-event-receiver.cc @@ -15,8 +15,10 @@ */ #include "aul-event-receiver.h" +#include #include // getpid #include +#include #include "trace.h" #ifdef HOST_TIZEN @@ -50,18 +52,27 @@ int AULEventReceiver::aulEventHandler(aul_type type, bundle* b, void* data) { return 0; } -bool AULEventReceiver::hasAulArguments(int argc, char* argv[]) { +bool AULEventReceiver::hasAulArguments(int argc, + char* argv[], + std::string& parsed_bundle) { bool result = false; bundle* parsed = bundle_import_from_argv(argc, argv); if (parsed) { if (bundle_get_val(parsed, AUL_K_STARTTIME)) { + std::ostringstream oss; + bundle_iterate( parsed, - [](const char* key, const char* value, void* d) { - LWNODE_DEV_LOGF("bundle - key: %s, value: %s", key, value); + [](const char* key, const char* value, void* data) { + std::ostringstream* oss = + reinterpret_cast(data); + *oss << "bundle - key: " << key << ", value: " << value + << std::endl; }, - NULL); + &oss); + + parsed_bundle = oss.str(); result = true; } bundle_free(parsed); @@ -71,21 +82,21 @@ bool AULEventReceiver::hasAulArguments(int argc, char* argv[]) { } bool AULEventReceiver::start(int argc, char* argv[]) { - isEventReceiverRunning_ = false; + std::string parsed_bundle; - if (hasAulArguments(argc, argv)) { - isEventReceiverRunning_ = true; + if (hasAulArguments(argc, argv, parsed_bundle)) { + aul_launch_init(aulEventHandler, nullptr); + aul_launch_argv_handler(argc, argv); char appid[kMaxPackageNameSize + 1]; aul_app_get_appid_bypid(getpid(), appid, kMaxPackageNameSize); - appid_ = appid; - initLoggerOutput(appid_); + appid_ = appid; - LWNODE_DEV_LOG("appid:", appid_); + initLoggerOutput(true, appid_); - aul_launch_init(aulEventHandler, nullptr); - aul_launch_argv_handler(argc, argv); + LWNODE_DEV_LOG(parsed_bundle); + LWNODE_DEV_LOG("appid: ", appid_); char* path = app_get_resource_path(); if (uv_chdir(path) != 0) { @@ -94,11 +105,14 @@ bool AULEventReceiver::start(int argc, char* argv[]) { exit(-errno); } free(path); - return isEventReceiverRunning_; + + assert(!appid_.empty()); + return isEventReceiverRunning(); } - initLoggerOutput(); - return isEventReceiverRunning_; + initLoggerOutput(false); + assert(appid_.empty()); + return isEventReceiverRunning(); } #endif @@ -108,18 +122,19 @@ AULEventReceiver* AULEventReceiver::getInstance() { } bool AULEventReceiver::isEventReceiverRunning() { - return isEventReceiverRunning_; + return !appid_.empty(); } -void AULEventReceiver::initLoggerOutput(const std::string tag) { +void AULEventReceiver::initLoggerOutput(bool isEventReceiverRunning, + const std::string tag) { if (!tag.empty()) { LogKind::user()->tag = tag; } - LogOption::setDefaultOutputInstantiator([&]() { + LogOption::setDefaultOutputInstantiator([&isEventReceiverRunning]() { static thread_local std::shared_ptr s_loggerOutput; if (s_loggerOutput == nullptr) { - s_loggerOutput = isEventReceiverRunning() + s_loggerOutput = isEventReceiverRunning ? std::static_pointer_cast( std::make_shared()) : std::static_pointer_cast( diff --git a/deps/node/src/lwnode/aul-event-receiver.h b/deps/node/src/lwnode/aul-event-receiver.h index 39337e368e..897287bb56 100644 --- a/deps/node/src/lwnode/aul-event-receiver.h +++ b/deps/node/src/lwnode/aul-event-receiver.h @@ -29,20 +29,18 @@ class AULEventReceiver { #ifdef HOST_TIZEN static int aulEventHandler(aul_type type, bundle* b, void* data); - bool hasAulArguments(int argc, char* argv[]); + bool hasAulArguments(int argc, char* argv[], std::string& parsed_bundle); bool start(int argc, char* argv[]); #else - bool start(int argc, char* argv[]) { - return false; - } + bool start(int argc, char* argv[]) { return false; } #endif - void initLoggerOutput(const std::string tag = ""); + void initLoggerOutput(bool isEventReceiverRunning, + const std::string tag = ""); bool isEventReceiverRunning(); private: AULEventReceiver() = default; - bool isEventReceiverRunning_{false}; static const int kMaxPackageNameSize{512}; std::string appid_; }; diff --git a/src/api/utils/logger/logger-impl.h b/src/api/utils/logger/logger-impl.h index e360c385c3..2f175ba172 100644 --- a/src/api/utils/logger/logger-impl.h +++ b/src/api/utils/logger/logger-impl.h @@ -23,6 +23,10 @@ #include #include +#ifndef LWNODE_EXPORT +#define LWNODE_EXPORT __attribute__((visibility("default"))) +#endif + class LogFormatter { public: std::string header(); @@ -154,7 +158,7 @@ class StdOut : public Logger::Output { using OutputInstantiator = std::function()>; -class LogOption { +class LWNODE_EXPORT LogOption { public: static void setDefaultOutputInstantiator(OutputInstantiator fn) { s_outputInstantiator_ = fn; @@ -166,8 +170,11 @@ class LogOption { static std::shared_ptr getDefalutOutput() { if (s_outputInstantiator_ == nullptr) { - // Set default output - s_outputInstantiator_ = []() { return std::make_shared(); }; + static std::shared_ptr default_output; + if (default_output == nullptr) { + default_output = std::make_shared(); + } + return default_output; } return s_outputInstantiator_(); } diff --git a/src/api/utils/logger/logger.cc b/src/api/utils/logger/logger.cc index 880fce1a7f..8f3d5a99d3 100644 --- a/src/api/utils/logger/logger.cc +++ b/src/api/utils/logger/logger.cc @@ -26,14 +26,11 @@ void DlogOut::flush(std::stringstream& ss, std::shared_ptr config) { auto c = config ? std::static_pointer_cast(config) : LogKind::lwnode(); - - // TODO: handle the case where users manually select a logging method. - #ifdef HOST_TIZEN dlog_print(DLOG_INFO, c->tag.c_str(), "%s", ss.str().c_str()); #else // For testing. StdOut will be used to flush buffers through stdout. - std::cerr << std::left << std::setfill(' ') << std::setw(6) << c->tag << " " + std::cout << std::left << std::setfill(' ') << std::setw(6) << c->tag << " " << ss.str(); #endif } diff --git a/src/api/utils/logger/logger.h b/src/api/utils/logger/logger.h index 878c8f4e1c..70720bf1c7 100644 --- a/src/api/utils/logger/logger.h +++ b/src/api/utils/logger/logger.h @@ -78,12 +78,12 @@ struct DLogConfig : Logger::Output::Config { std::string tag; }; -class LWNodeLogger : public Logger { +class LWNODE_EXPORT LWNodeLogger : public Logger { public: LWNodeLogger(std::shared_ptr config) { outConfig_ = config; } }; -class DlogOut : public Logger::Output { +class LWNODE_EXPORT DlogOut : public Logger::Output { public: void flush(std::stringstream& ss, std::shared_ptr config = nullptr) override; @@ -91,7 +91,7 @@ class DlogOut : public Logger::Output { bool hasAutoAppendEndOfLine() override { return true; } }; -class LogKind { +class LWNODE_EXPORT LogKind { public: static std::shared_ptr user() { return getInstance()->user_; } static std::shared_ptr lwnode() { return getInstance()->lwnode_; }