1
0
Fork 0
forked from lthn/blockchain

added logs initializaion

This commit is contained in:
cryptozoidberg 2020-01-28 18:23:09 +01:00
parent 488be10664
commit e690673498
No known key found for this signature in database
GPG key ID: 22DEB97A54C6FDEC

View file

@ -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<int64_t, plain_wallet::plain_wallet_api_impl*> ginstances;
epee::critical_section ginstances_lock;
std::atomic<int64_t> gcounter(1);
std::atomic<bool> glogs_initialized(false);
#define GENERAL_INTERNAL_ERRROR_INSTANCE "GENERAL_INTERNAL_ERROR: WALLET INSTNACE NOT FOUND"
@ -25,10 +28,29 @@ std::atomic<int64_t> 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);