Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Config option for single line logging records #2214

Merged
merged 1 commit into from
Aug 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions nano/core_test/logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,25 @@ TEST (logging, upgrade_v6_v7)
ASSERT_EQ (false, tree.get<bool> ("network_timeout_logging_value"));
}

TEST (logging, upgrade_v7_v8)
{
auto path1 (nano::unique_path ());
auto path2 (nano::unique_path ());
nano::logging logging1;
logging1.init (path1);
nano::logging logging2;
logging2.init (path2);
nano::jsonconfig tree;
logging1.serialize_json (tree);
tree.erase ("version");
tree.erase ("single_line_record");
bool upgraded (false);
ASSERT_FALSE (logging2.deserialize_json (upgraded, tree));
ASSERT_TRUE (upgraded);
ASSERT_LE (8, tree.get<int> ("version"));
ASSERT_EQ (false, tree.get<bool> ("single_line_record"));
}

TEST (logger, changing_time_interval)
{
auto path1 (nano::unique_path ());
Expand Down
20 changes: 10 additions & 10 deletions nano/lib/blocks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,12 +227,12 @@ bool nano::send_block::deserialize (nano::stream & stream_a)
return error;
}

void nano::send_block::serialize_json (std::string & string_a) const
void nano::send_block::serialize_json (std::string & string_a, bool single_line) const
{
boost::property_tree::ptree tree;
serialize_json (tree);
std::stringstream ostream;
boost::property_tree::write_json (ostream, tree);
boost::property_tree::write_json (ostream, tree, !single_line);
string_a = ostream.str ();
}

Expand Down Expand Up @@ -547,12 +547,12 @@ bool nano::open_block::deserialize (nano::stream & stream_a)
return error;
}

void nano::open_block::serialize_json (std::string & string_a) const
void nano::open_block::serialize_json (std::string & string_a, bool single_line) const
{
boost::property_tree::ptree tree;
serialize_json (tree);
std::stringstream ostream;
boost::property_tree::write_json (ostream, tree);
boost::property_tree::write_json (ostream, tree, !single_line);
string_a = ostream.str ();
}

Expand Down Expand Up @@ -789,12 +789,12 @@ bool nano::change_block::deserialize (nano::stream & stream_a)
return error;
}

void nano::change_block::serialize_json (std::string & string_a) const
void nano::change_block::serialize_json (std::string & string_a, bool single_line) const
{
boost::property_tree::ptree tree;
serialize_json (tree);
std::stringstream ostream;
boost::property_tree::write_json (ostream, tree);
boost::property_tree::write_json (ostream, tree, !single_line);
string_a = ostream.str ();
}

Expand Down Expand Up @@ -1077,12 +1077,12 @@ bool nano::state_block::deserialize (nano::stream & stream_a)
return error;
}

void nano::state_block::serialize_json (std::string & string_a) const
void nano::state_block::serialize_json (std::string & string_a, bool single_line) const
{
boost::property_tree::ptree tree;
serialize_json (tree);
std::stringstream ostream;
boost::property_tree::write_json (ostream, tree);
boost::property_tree::write_json (ostream, tree, !single_line);
string_a = ostream.str ();
}

Expand Down Expand Up @@ -1349,12 +1349,12 @@ bool nano::receive_block::deserialize (nano::stream & stream_a)
return error;
}

void nano::receive_block::serialize_json (std::string & string_a) const
void nano::receive_block::serialize_json (std::string & string_a, bool single_line) const
{
boost::property_tree::ptree tree;
serialize_json (tree);
std::stringstream ostream;
boost::property_tree::write_json (ostream, tree);
boost::property_tree::write_json (ostream, tree, !single_line);
string_a = ostream.str ();
}

Expand Down
12 changes: 6 additions & 6 deletions nano/lib/blocks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class block
virtual nano::block_hash link () const;
virtual nano::account representative () const;
virtual void serialize (nano::stream &) const = 0;
virtual void serialize_json (std::string &) const = 0;
virtual void serialize_json (std::string &, bool = false) const = 0;
virtual void serialize_json (boost::property_tree::ptree &) const = 0;
virtual void visit (nano::block_visitor &) const = 0;
virtual bool operator== (nano::block const &) const = 0;
Expand Down Expand Up @@ -117,7 +117,7 @@ class send_block : public nano::block
nano::block_hash root () const override;
void serialize (nano::stream &) const override;
bool deserialize (nano::stream &);
void serialize_json (std::string &) const override;
void serialize_json (std::string &, bool = false) const override;
void serialize_json (boost::property_tree::ptree &) const override;
bool deserialize_json (boost::property_tree::ptree const &);
void visit (nano::block_visitor &) const override;
Expand Down Expand Up @@ -161,7 +161,7 @@ class receive_block : public nano::block
nano::block_hash root () const override;
void serialize (nano::stream &) const override;
bool deserialize (nano::stream &);
void serialize_json (std::string &) const override;
void serialize_json (std::string &, bool = false) const override;
void serialize_json (boost::property_tree::ptree &) const override;
bool deserialize_json (boost::property_tree::ptree const &);
void visit (nano::block_visitor &) const override;
Expand Down Expand Up @@ -209,7 +209,7 @@ class open_block : public nano::block
nano::account representative () const override;
void serialize (nano::stream &) const override;
bool deserialize (nano::stream &);
void serialize_json (std::string &) const override;
void serialize_json (std::string &, bool = false) const override;
void serialize_json (boost::property_tree::ptree &) const override;
bool deserialize_json (boost::property_tree::ptree const &);
void visit (nano::block_visitor &) const override;
Expand Down Expand Up @@ -253,7 +253,7 @@ class change_block : public nano::block
nano::account representative () const override;
void serialize (nano::stream &) const override;
bool deserialize (nano::stream &);
void serialize_json (std::string &) const override;
void serialize_json (std::string &, bool = false) const override;
void serialize_json (boost::property_tree::ptree &) const override;
bool deserialize_json (boost::property_tree::ptree const &);
void visit (nano::block_visitor &) const override;
Expand Down Expand Up @@ -312,7 +312,7 @@ class state_block : public nano::block
nano::account representative () const override;
void serialize (nano::stream &) const override;
bool deserialize (nano::stream &);
void serialize_json (std::string &) const override;
void serialize_json (std::string &, bool = false) const override;
void serialize_json (boost::property_tree::ptree &) const override;
bool deserialize_json (boost::property_tree::ptree const &);
void visit (nano::block_visitor &) const override;
Expand Down
2 changes: 1 addition & 1 deletion nano/node/blockprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ nano::process_return nano::block_processor::process_one (nano::transaction const
if (node.config.logging.ledger_logging ())
{
std::string block;
info_a.block->serialize_json (block);
info_a.block->serialize_json (block, node.config.logging.single_line_record ());
node.logger.try_log (boost::str (boost::format ("Processing block %1%: %2%") % hash.to_string () % block));
}
if (info_a.modified > nano::seconds_since_epoch () - 300 && node.block_arrival.recent (hash))
Expand Down
2 changes: 1 addition & 1 deletion nano/node/bootstrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ void nano::bulk_pull_client::received_block (boost::system::error_code const & e
if (connection->node->config.logging.bulk_pull_logging ())
{
std::string block_l;
block->serialize_json (block_l);
block->serialize_json (block_l, connection->node->config.logging.single_line_record ());
connection->node->logger.try_log (boost::str (boost::format ("Pulled block %1% %2%") % hash.to_string () % block_l));
}
// Is block expected?
Expand Down
7 changes: 4 additions & 3 deletions nano/node/election.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,15 @@ void nano::election::confirm_if_quorum (nano::transaction const & transaction_a)
void nano::election::log_votes (nano::tally_t const & tally_a) const
{
std::stringstream tally;
tally << boost::str (boost::format ("\nVote tally for root %1%") % status.winner->root ().to_string ());
std::string line_end (node.config.logging.single_line_record () ? "\t" : "\n");
tally << boost::str (boost::format ("%1%Vote tally for root %2%") % line_end % status.winner->root ().to_string ());
for (auto i (tally_a.begin ()), n (tally_a.end ()); i != n; ++i)
{
tally << boost::str (boost::format ("\nBlock %1% weight %2%") % i->second->hash ().to_string () % i->first.convert_to<std::string> ());
tally << boost::str (boost::format ("%1%Block %2% weight %3%") % line_end % i->second->hash ().to_string () % i->first.convert_to<std::string> ());
}
for (auto i (last_votes.begin ()), n (last_votes.end ()); i != n; ++i)
{
tally << boost::str (boost::format ("\n%1% %2%") % i->first.to_account () % i->second.hash.to_string ());
tally << boost::str (boost::format ("%1%%2% %3%") % line_end % i->first.to_account () % i->second.hash.to_string ());
}
node.logger.try_log (tally.str ());
}
Expand Down
9 changes: 9 additions & 0 deletions nano/node/logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ nano::error nano::logging::serialize_json (nano::jsonconfig & json) const
json.put ("rotation_size", rotation_size);
json.put ("flush", flush);
json.put ("min_time_between_output", min_time_between_log_output.count ());
json.put ("single_line_record", single_line_record_value);
return json.get_error ();
}

Expand Down Expand Up @@ -135,6 +136,8 @@ bool nano::logging::upgrade_json (unsigned version_a, nano::jsonconfig & json)
json.erase ("log_rpc");
break;
case 7:
json.put ("single_line_record", single_line_record_value);
case 8:
break;
default:
throw std::runtime_error ("Unknown logging_config version");
Expand Down Expand Up @@ -183,6 +186,7 @@ nano::error nano::logging::deserialize_json (bool & upgraded_a, nano::jsonconfig
json.get<bool> ("timing", timing_logging_value);
json.get<bool> ("log_to_cerr", log_to_cerr_value);
json.get<bool> ("flush", flush);
json.get<bool> ("single_line_record", single_line_record_value);
json.get<uintmax_t> ("max_size", max_size);
json.get<uintmax_t> ("rotation_size", rotation_size);
uintmax_t min_time_between_log_output_raw;
Expand Down Expand Up @@ -285,3 +289,8 @@ bool nano::logging::log_to_cerr () const
{
return log_to_cerr_value;
}

bool nano::logging::single_line_record () const
{
return single_line_record_value;
}
4 changes: 3 additions & 1 deletion nano/node/logging.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class logging final
bool callback_logging () const;
bool work_generation_time () const;
bool log_to_cerr () const;
bool single_line_record () const;
void init (boost::filesystem::path const &);

bool ledger_logging_value{ false };
Expand All @@ -64,10 +65,11 @@ class logging final
uintmax_t max_size{ 128 * 1024 * 1024 };
uintmax_t rotation_size{ 4 * 1024 * 1024 };
std::chrono::milliseconds min_time_between_log_output{ 5 };
bool single_line_record_value{ false };
static void release_file_sink ();
unsigned json_version () const
{
return 7;
return 8;
}

private:
Expand Down