initial easylogging++ support added to openmonero

pull/93/merge
moneroexamples 6 years ago
parent e074eba4e5
commit 62480adced

@ -1,3 +1,4 @@
#include "src/om_log.h"
#include "src/CmdLineOptions.h"
#include "src/MicroCore.h"
#include "src/YourMoneroRequests.h"
@ -29,6 +30,25 @@ if (*help_opt)
return EXIT_SUCCESS;
}
mlog_configure(mlog_get_default_log_path(""), true);
mlog_set_log("1");
// set logger for Open Monero
el::Configurations defaultConf;
defaultConf.setToDefault();
defaultConf.setGlobally(el::ConfigurationType::ToFile,
std::string("false"));
defaultConf.setGlobally(el::ConfigurationType::ToStandardOutput,
std::string("true"));
//el::Logger* omLogger = el::Loggers::getLogger("openmonero");
el::Loggers::reconfigureLogger("openmonero", defaultConf);
OMINFO << "OpenMonero is starting";
auto do_not_relay_opt = opts.get_option<bool>("do-not-relay");
auto testnet_opt = opts.get_option<bool>("testnet");
auto stagenet_opt = opts.get_option<bool>("stagenet");
@ -42,7 +62,8 @@ bool do_not_relay = *do_not_relay_opt;
if (testnet && stagenet)
{
cerr << "testnet and stagenet cannot be specified at the same time!" << endl;
//cerr << "testnet and stagenet cannot be specified at the same time!" << endl;
OMERROR << "testnet and stagenet cannot be specified at the same time!";
return EXIT_FAILURE;
}
@ -56,8 +77,7 @@ cryptonote::network_type nettype = testnet ?
xmreg::BlockchainSetup bc_setup {nettype, do_not_relay, *config_file_opt};
cout << "Using blockchain path: " << bc_setup.blockchain_path << endl;
OMINFO << "Using blockchain path: " << bc_setup.blockchain_path;
nlohmann::json config_json = bc_setup.get_config();
@ -99,10 +119,13 @@ auto current_bc_status
// with the deamon.
if (!current_bc_status->init_monero_blockchain())
{
cerr << "Error accessing blockchain." << endl;
OMERROR << "Error accessing blockchain.";
return EXIT_FAILURE;
}
//LOG_PRINT_L0("Initializing source blockchain (BlockchainDB)");
// launch the status monitoring thread so that it keeps track of blockchain
// info, e.g., current height. Information from this thread is used
// by tx searching threads that are launched for each user independently,
@ -120,7 +143,7 @@ try
}
catch(std::exception const& e)
{
cerr << e.what() << '\n';
OMERROR << e.what();
return EXIT_FAILURE;
}
@ -200,14 +223,14 @@ if (config_json["ssl"]["enable"])
// can check using: curl -k -v -w'\n' -X POST 'https://127.0.0.1:1984/get_version'
cout << "Start the service at https://127.0.0.1:" << app_port << endl;
OMINFO << "Start the service at https://127.0.0.1:" << app_port;
}
else
{
settings->set_port(app_port);
settings->set_default_header( "Connection", "close" );
cout << "Start the service at http://127.0.0.1:" << app_port << endl;
OMINFO << "Start the service at http://127.0.0.1:" << app_port;
}

@ -36,7 +36,8 @@ BlockchainSetup::BlockchainSetup(
void
BlockchainSetup::parse_addr_and_viewkey()
{
if (import_payment_address_str.empty() || import_payment_viewkey_str.empty())
if (import_payment_address_str.empty()
|| import_payment_viewkey_str.empty())
std::runtime_error("config address or viewkey are empty.");
@ -47,7 +48,8 @@ BlockchainSetup::parse_addr_and_viewkey()
import_payment_address,
net_type))
{
throw std::runtime_error("Cant parse config address: " + import_payment_address_str);
throw std::runtime_error("Cant parse config address: "
+ import_payment_address_str);
}
@ -55,7 +57,8 @@ BlockchainSetup::parse_addr_and_viewkey()
import_payment_viewkey_str,
import_payment_viewkey))
{
throw std::runtime_error("Cant parse config viewkey: " + import_payment_viewkey_str);
throw std::runtime_error("Cant parse config viewkey: "
+ import_payment_viewkey_str);
}
}
@ -72,7 +75,8 @@ BlockchainSetup::get_blockchain_path()
switch (net_type)
{
case network_type::MAINNET:
blockchain_path = config_json["blockchain-path"]["mainnet"].get<string>();
blockchain_path = config_json["blockchain-path"]["mainnet"]
.get<string>();
deamon_url = config_json["daemon-url"]["mainnet"];
import_payment_address_str
= config_json["wallet_import"]["mainnet"]["address"];
@ -80,7 +84,8 @@ BlockchainSetup::get_blockchain_path()
= config_json["wallet_import"]["mainnet"]["viewkey"];
break;
case network_type::TESTNET:
blockchain_path = config_json["blockchain-path"]["testnet"].get<string>();
blockchain_path = config_json["blockchain-path"]["testnet"]
.get<string>();
deamon_url = config_json["daemon-url"]["testnet"];
import_payment_address_str
= config_json["wallet_import"]["testnet"]["address"];
@ -88,7 +93,8 @@ BlockchainSetup::get_blockchain_path()
= config_json["wallet_import"]["testnet"]["viewkey"];
break;
case network_type::STAGENET:
blockchain_path = config_json["blockchain-path"]["stagenet"].get<string>();
blockchain_path = config_json["blockchain-path"]["stagenet"]
.get<string>();
deamon_url = config_json["daemon-url"]["stagenet"];
import_payment_address_str
= config_json["wallet_import"]["stagenet"]["address"];
@ -128,7 +134,8 @@ BlockchainSetup::read_config(string config_json_path)
{
// check if config-file provided exist
if (!boost::filesystem::exists(config_json_path))
throw std::runtime_error("Config file " + config_json_path + " does not exist");
throw std::runtime_error("Config file " + config_json_path
+ " does not exist");
json _config;
@ -140,7 +147,8 @@ BlockchainSetup::read_config(string config_json_path)
}
catch (const std::exception& e)
{
throw std::runtime_error(string{"Cant parse json string as json: "} + e.what());
throw std::runtime_error(string{"Cant parse json string as json: "}
+ e.what());
}
return _config;
@ -151,15 +159,20 @@ BlockchainSetup::read_config(string config_json_path)
void
BlockchainSetup::_init()
{
refresh_block_status_every_seconds = config_json["refresh_block_status_every_seconds"];
blocks_search_lookahead = config_json["blocks_search_lookahead"];
max_number_of_blocks_to_import = config_json["max_number_of_blocks_to_import"];
search_thread_life_in_seconds = config_json["search_thread_life_in_seconds"];
import_fee = config_json["wallet_import"]["fee"];
refresh_block_status_every_seconds
= config_json["refresh_block_status_every_seconds"];
blocks_search_lookahead
= config_json["blocks_search_lookahead"];
max_number_of_blocks_to_import
= config_json["max_number_of_blocks_to_import"];
search_thread_life_in_seconds
= config_json["search_thread_life_in_seconds"];
import_fee
= config_json["wallet_import"]["fee"];
get_blockchain_path();
parse_addr_and_viewkey();
}
}
}

@ -40,9 +40,8 @@ CurrentBlockchainStatus::start_monitor_blockchain_thread()
{
update_current_blockchain_height();
read_mempool();
cout << "Check block height: " << current_height
<< " no of mempool txs: " << mempool_txs.size()
<< '\n';
OMINFO << "Check block height: " << current_height
<< " no of mempool txs: " << mempool_txs.size();
clean_search_thread_map();
std::this_thread::sleep_for(
std::chrono::seconds(
@ -72,10 +71,6 @@ CurrentBlockchainStatus::update_current_blockchain_height()
bool
CurrentBlockchainStatus::init_monero_blockchain()
{
// set monero log output level
uint32_t log_level = 0;
mlog_configure(mlog_get_default_log_path(""), true);
// initialize the core using the blockchain path
return mcore->init(bc_setup.blockchain_path, bc_setup.net_type);}

@ -7,6 +7,7 @@
#define MYSQLPP_SSQLS_NO_STATICS 1
#include "om_log.h"
#include "MicroCore.h"
#include "ssqlses.h"
#include "TxUnlockChecker.h"

@ -0,0 +1,10 @@
#ifndef OM_LOG_H
#define OM_LOG_H
#define OPENMONERO_LOG_CATEGORY "openmonero"
#define OMINFO CLOG(INFO, OPENMONERO_LOG_CATEGORY)
#define OMWARN CLOG(WARNING, OPENMONERO_LOG_CATEGORY)
#define OMERROR CLOG(ERROR, OPENMONERO_LOG_CATEGORY)
#endif // OM_LOG_H
Loading…
Cancel
Save