diff --git a/src/wallet/plain_wallet_api.cpp b/src/wallet/plain_wallet_api.cpp index 6744999d..b7d0847d 100644 --- a/src/wallet/plain_wallet_api.cpp +++ b/src/wallet/plain_wallet_api.cpp @@ -5,11 +5,14 @@ #include "plain_wallet_api.h" #include "plain_wallet_api_impl.h" +#include "currency_core/currency_config.h" +#include "version.h" //TODO: global objects, need refactoring. Just temporary solution std::map ginstances; epee::critical_section ginstances_lock; std::atomic gcounter(1); +std::atomic glogs_initialized(false); #define GENERAL_INTERNAL_ERRROR_INSTANCE "GENERAL_INTERNAL_ERROR: WALLET INSTNACE NOT FOUND" @@ -25,10 +28,29 @@ std::atomic gcounter(1); CRITICAL_REGION_END(); + + namespace plain_wallet { + void initialize_logs() + { + char buffer[1000] = {}; + strcpy(buffer, getenv("HOME")); + std::string log_dir = buffer; + log_dir += "/Documents"; + epee::log_space::get_set_log_detalisation_level(true, LOG_LEVEL_2); + epee::log_space::log_singletone::add_logger(LOGGER_CONSOLE, NULL, NULL); + epee::log_space::log_singletone::add_logger(LOGGER_FILE, "plain_wallet.log", log_dir.c_str()); + LOG_PRINT_L0("Plain wallet initialized: " << CURRENCY_NAME << " v" << PROJECT_VERSION_LONG); + + glogs_initialized = true; + } + hwallet create_instance(const std::string& ip, const std::string& port) { + if (!glogs_initialized) + initialize_logs(); + plain_wallet_api_impl* ptr = new plain_wallet_api_impl(ip, port); hwallet new_h = gcounter++; CRITICAL_REGION_BEGIN(ginstances_lock);