Skip to content

Commit

Permalink
Ensure logging objects are constructed on first used
Browse files Browse the repository at this point in the history
This makes it safe to log messages during static initialization.
  • Loading branch information
CelticMinstrel committed Mar 20, 2016
1 parent 5eb9d80 commit 8e58897
Show file tree
Hide file tree
Showing 48 changed files with 155 additions and 125 deletions.
2 changes: 1 addition & 1 deletion src/ai/composite/goal.cpp
Expand Up @@ -306,7 +306,7 @@ protect_goal::protect_goal(readonly_context &context, const config &cfg, bool pr
, value_(1.0) //this default value taken from old code
{
if(protect_only_own_unit_) {
lg::wml_error << deprecate_wml_key_warning("protect_my_unit", "1.13.0") << "\n";
lg::wml_error() << deprecate_wml_key_warning("protect_my_unit", "1.13.0") << "\n";
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/ai/configuration.cpp
Expand Up @@ -402,7 +402,7 @@ bool configuration::upgrade_side_config_from_1_07_02_to_1_07_03(side_number side


BOOST_FOREACH(const config &aitarget, aiparam.child_range("target")) {
lg::wml_error << deprecate_wml_key_warning("target", "1.13.0") << "\n";
lg::wml_error() << deprecate_wml_key_warning("target", "1.13.0") << "\n";
config aigoal;
transfer_turns_and_time_of_day_data(aiparam,aigoal);

Expand All @@ -421,15 +421,15 @@ bool configuration::upgrade_side_config_from_1_07_02_to_1_07_03(side_number side


BOOST_FOREACH(config &ai_protect_unit, aiparam.child_range("protect_unit")) {
lg::wml_error << deprecate_wml_key_warning("protect_unit", "1.13.0") << "\n";
lg::wml_error() << deprecate_wml_key_warning("protect_unit", "1.13.0") << "\n";
transfer_turns_and_time_of_day_data(aiparam,ai_protect_unit);
upgrade_protect_goal_config_from_1_07_02_to_1_07_03(side,ai_protect_unit,parsed_cfg,true);
}
aiparam.clear_children("protect_unit");


BOOST_FOREACH(config &ai_protect_location, aiparam.child_range("protect_location")) {
lg::wml_error << deprecate_wml_key_warning("protect_location", "1.13.0") << "\n";
lg::wml_error() << deprecate_wml_key_warning("protect_location", "1.13.0") << "\n";
transfer_turns_and_time_of_day_data(aiparam,ai_protect_location);
upgrade_protect_goal_config_from_1_07_02_to_1_07_03(side,ai_protect_location,parsed_cfg,false);
}
Expand All @@ -438,14 +438,14 @@ bool configuration::upgrade_side_config_from_1_07_02_to_1_07_03(side_number side

if (const config::attribute_value *v = aiparam.get("protect_leader"))
{
lg::wml_error << deprecate_wml_key_warning("protect_leader", "1.13.0") << "\n";
lg::wml_error() << deprecate_wml_key_warning("protect_leader", "1.13.0") << "\n";
config c;
c["value"] = *v;
c["canrecruit"] = true;
c["side_number"] = side;
transfer_turns_and_time_of_day_data(aiparam,c);
if (const config::attribute_value *v = aiparam.get("protect_leader_radius")) {
lg::wml_error << deprecate_wml_key_warning("protect_leader_radius", "1.13.0") << "\n";
lg::wml_error() << deprecate_wml_key_warning("protect_leader_radius", "1.13.0") << "\n";
c["radius"] = *v;
}

Expand Down
2 changes: 1 addition & 1 deletion src/ai/default/ai.cpp
Expand Up @@ -746,7 +746,7 @@ class combat_score_less {

static void debug_print_recall_list_scores(const std::vector< std::pair<std::string,double> > &recall_list_scores,const char *message)
{
if (!lg::debug.dont_log(log_ai)) {
if (!lg::debug().dont_log(log_ai)) {
std::stringstream s;
s << message << std::endl;
for (std::vector< std::pair<std::string,double> >::const_iterator p = recall_list_scores.begin(); p!=recall_list_scores.end();++p) {
Expand Down
6 changes: 3 additions & 3 deletions src/ai/recruitment/recruitment.cpp
Expand Up @@ -230,7 +230,7 @@ void recruitment::execute() {
// Add team recruits.
BOOST_FOREACH(const std::string& recruit, current_team().recruits()) {
if (!unit_types.find(recruit)) {
lg::wml_error << "Unit-type \"" << recruit << "\" doesn't exist.\n";
lg::wml_error() << "Unit-type \"" << recruit << "\" doesn't exist.\n";
}
data.recruits.insert(recruit);
data.scores[recruit] = 0.0;
Expand All @@ -240,7 +240,7 @@ void recruitment::execute() {
// Add extra recruits.
BOOST_FOREACH(const std::string& recruit, leader->recruits()) {
if (!unit_types.find(recruit)) {
lg::wml_error << "Unit-type \"" << recruit << "\" doesn't exist.\n";
lg::wml_error() << "Unit-type \"" << recruit << "\" doesn't exist.\n";
}
data.recruits.insert(recruit);
data.scores[recruit] = 0.0;
Expand Down Expand Up @@ -291,7 +291,7 @@ void recruitment::execute() {
update_important_hexes();
// Show "x" on important hexes if debug mode is activated AND
// the log domain "ai/recruitment" is used.
if (game_config::debug && !lg::info.dont_log(log_ai_recruitment)) {
if (game_config::debug && !lg::info().dont_log(log_ai_recruitment)) {
show_important_hexes();
}

Expand Down
2 changes: 1 addition & 1 deletion src/ai/testing/ca.cpp
Expand Up @@ -994,7 +994,7 @@ void get_villages_phase::get_villages(
leader_loc_ = map_location::null_location();
}

debug_ = !lg::debug.dont_log(log_ai_testing_ai_default);
debug_ = !lg::debug().dont_log(log_ai_testing_ai_default);

// Find our units who can move.
treachmap reachmap;
Expand Down
2 changes: 1 addition & 1 deletion src/campaign_server/addon_utils.cpp
Expand Up @@ -24,7 +24,7 @@
#include <boost/foreach.hpp>

static lg::log_domain log_network("network");
#define LOG_CS if (lg::err.dont_log(log_network)) ; else lg::err(log_network, false)
#define LOG_CS if (lg::err().dont_log(log_network)) ; else lg::err()(log_network, false)

namespace {

Expand Down
2 changes: 1 addition & 1 deletion src/campaign_server/campaign_server.cpp
Expand Up @@ -875,7 +875,7 @@ int main(int argc, char**argv)
{
game_config::path = filesystem::get_cwd();

lg::set_log_domain_severity("campaignd", lg::info);
lg::set_log_domain_severity("campaignd", lg::info());
lg::timestamps(true);

try {
Expand Down
10 changes: 5 additions & 5 deletions src/commandline_options.cpp
Expand Up @@ -357,13 +357,13 @@ commandline_options::commandline_options (const std::vector<std::string>& args)
if (vm.count("load"))
load = vm["load"].as<std::string>();
if (vm.count("log-error"))
parse_log_domains_(vm["log-error"].as<std::string>(),lg::err.get_severity());
parse_log_domains_(vm["log-error"].as<std::string>(),lg::err().get_severity());
if (vm.count("log-warning"))
parse_log_domains_(vm["log-warning"].as<std::string>(),lg::warn.get_severity());
parse_log_domains_(vm["log-warning"].as<std::string>(),lg::warn().get_severity());
if (vm.count("log-info"))
parse_log_domains_(vm["log-info"].as<std::string>(),lg::info.get_severity());
parse_log_domains_(vm["log-info"].as<std::string>(),lg::info().get_severity());
if (vm.count("log-debug"))
parse_log_domains_(vm["log-debug"].as<std::string>(),lg::debug.get_severity());
parse_log_domains_(vm["log-debug"].as<std::string>(),lg::debug().get_severity());
if (vm.count("logdomains"))
logdomains = vm["logdomains"].as<std::string>();
if (vm.count("log-precise"))
Expand Down Expand Up @@ -498,7 +498,7 @@ void commandline_options::parse_log_domains_(const std::string &domains_string,
}

void commandline_options::parse_log_strictness (const std::string & severity ) {
static lg::logger const *loggers[] = { &lg::err, &lg::warn, &lg::info, &lg::debug };
static lg::logger const *loggers[] = { &lg::err(), &lg::warn(), &lg::info(), &lg::debug() };
BOOST_FOREACH (const lg::logger * l, loggers ) {
if (severity == l->get_name()) {
lg::set_strict_severity(*l);
Expand Down
4 changes: 2 additions & 2 deletions src/config.cpp
Expand Up @@ -509,7 +509,7 @@ bool config::has_old_attribute(const std::string &key, const std::string &old_ke
return true;
} else if (values.find(old_key) != values.end()) {
if (!msg.empty())
lg::wml_error << msg;
lg::wml_error() << msg;
return true;
}
return false;
Expand Down Expand Up @@ -903,7 +903,7 @@ const config::attribute_value &config::get_old_attribute(const std::string &key,
i = values.find(old_key);
if (i != values.end()) {
if (!msg.empty())
lg::wml_error << msg;
lg::wml_error() << msg;
return i->second;
}

Expand Down
10 changes: 5 additions & 5 deletions src/game_events/action_wml.cpp
Expand Up @@ -257,7 +257,7 @@ void handle_deprecated_message(const config& cfg)
{
// Note: no need to translate the string, since only used for deprecated things.
const std::string& message = cfg["message"];
lg::wml_error << message << '\n';
lg::wml_error() << message << '\n';
}

void handle_wml_log_message(const config& cfg)
Expand Down Expand Up @@ -642,7 +642,7 @@ WML_HANDLER_FUNCTION(replace_map, cfg)
}
} catch(incorrect_map_format_error&) {
const std::string log_map_name = cfg["map"].empty() ? cfg["file"] : std::string("from inline data");
lg::wml_error << "replace_map: Unable to load map " << log_map_name << std::endl;
lg::wml_error() << "replace_map: Unable to load map " << log_map_name << std::endl;
return;
} catch(twml_exception& e) {
e.show(resources::screen->video());
Expand All @@ -652,23 +652,23 @@ WML_HANDLER_FUNCTION(replace_map, cfg)
if (map.total_width() > game_map->total_width()
|| map.total_height() > game_map->total_height()) {
if (!cfg["expand"].to_bool()) {
lg::wml_error << "replace_map: Map dimension(s) increase but expand is not set" << std::endl;
lg::wml_error() << "replace_map: Map dimension(s) increase but expand is not set" << std::endl;
return;
}
}

if (map.total_width() < game_map->total_width()
|| map.total_height() < game_map->total_height()) {
if (!cfg["shrink"].to_bool()) {
lg::wml_error << "replace_map: Map dimension(s) decrease but shrink is not set" << std::endl;
lg::wml_error() << "replace_map: Map dimension(s) decrease but shrink is not set" << std::endl;
return;
}
}

boost::optional<std::string> errmsg = resources::gameboard->replace_map(map);

if (errmsg) {
lg::wml_error << *errmsg << std::endl;
lg::wml_error() << *errmsg << std::endl;
}

resources::screen->reload_map();
Expand Down
2 changes: 1 addition & 1 deletion src/game_events/manager_impl.cpp
Expand Up @@ -46,7 +46,7 @@ namespace game_events {

void t_event_handlers::log_handlers()
{
if(lg::debug.dont_log("event_handler")) return;
if(lg::debug().dont_log("event_handler")) return;

std::stringstream ss;

Expand Down
16 changes: 8 additions & 8 deletions src/game_events/pump.cpp
Expand Up @@ -383,7 +383,7 @@ namespace { // Support functions
{
static const std::string caption("Invalid WML found");

show_wml_messages(lg::wml_error, caption, true);
show_wml_messages(lg::wml_error(), caption, true);
}

/**
Expand Down Expand Up @@ -459,13 +459,13 @@ void t_pump::context_skip_messages(bool b)
void t_pump::put_wml_message(const std::string& logger, const std::string& message, bool in_chat)
{
if (logger == "err" || logger == "error") {
put_wml_message(lg::err, _("Error: "), message, in_chat );
put_wml_message(lg::err(), _("Error: "), message, in_chat );
} else if (logger == "warn" || logger == "wrn" || logger == "warning") {
put_wml_message(lg::warn, _("Warning: "), message, in_chat );
} else if ((logger == "debug" || logger == "dbg") && !lg::debug.dont_log(log_wml)) {
put_wml_message(lg::debug, _("Debug: "), message, in_chat );
} else if (!lg::info.dont_log(log_wml)) {
put_wml_message(lg::info, _("Info: "), message, in_chat );
put_wml_message(lg::warn(), _("Warning: "), message, in_chat );
} else if ((logger == "debug" || logger == "dbg") && !lg::debug().dont_log(log_wml)) {
put_wml_message(lg::debug(), _("Debug: "), message, in_chat );
} else if (!lg::info().dont_log(log_wml)) {
put_wml_message(lg::info(), _("Info: "), message, in_chat );
}
}

Expand Down Expand Up @@ -506,7 +506,7 @@ bool t_pump::operator()()
<< "recursion level would exceed maximum: " << game_config::max_loop << '\n';
return false;
}
if(!lg::debug.dont_log("event_handler")) {
if(!lg::debug().dont_log("event_handler")) {
std::stringstream ss;
BOOST_FOREACH(const queued_event& ev, impl_->events_queue) {
ss << "name=" << ev.name << "; ";
Expand Down
6 changes: 3 additions & 3 deletions src/game_launcher.cpp
Expand Up @@ -92,9 +92,9 @@ static lg::log_domain log_config("config");
#define WRN_CONFIG LOG_STREAM(warn, log_config)
#define LOG_CONFIG LOG_STREAM(info, log_config)

#define LOG_GENERAL LOG_STREAM(info, lg::general)
#define WRN_GENERAL LOG_STREAM(warn, lg::general)
#define DBG_GENERAL LOG_STREAM(debug, lg::general)
#define LOG_GENERAL LOG_STREAM(info, lg::general())
#define WRN_GENERAL LOG_STREAM(warn, lg::general())
#define DBG_GENERAL LOG_STREAM(debug, lg::general())

static lg::log_domain log_mp_create("mp/create");
#define DBG_MP LOG_STREAM(debug, log_mp_create)
Expand Down
8 changes: 4 additions & 4 deletions src/gettext_boost.cpp
Expand Up @@ -24,10 +24,10 @@
#include <boost/thread.hpp>
#include <set>

#define DBG_G LOG_STREAM(debug, lg::general)
#define LOG_G LOG_STREAM(info, lg::general)
#define WRN_G LOG_STREAM(warn, lg::general)
#define ERR_G LOG_STREAM(err, lg::general)
#define DBG_G LOG_STREAM(debug, lg::general())
#define LOG_G LOG_STREAM(info, lg::general())
#define WRN_G LOG_STREAM(warn, lg::general())
#define ERR_G LOG_STREAM(err, lg::general())

namespace bl = boost::locale;
namespace
Expand Down
4 changes: 2 additions & 2 deletions src/gui/auxiliary/log.hpp
Expand Up @@ -45,10 +45,10 @@ extern lg::log_domain log_gui_general;

extern lg::log_domain log_gui_iterator;
#define TST_GUI_I \
if(lg::debug.dont_log(gui2::log_gui_iterator)) \
if(lg::debug().dont_log(gui2::log_gui_iterator)) \
; \
else \
lg::debug(gui2::log_gui_iterator, false, false)
lg::debug()(gui2::log_gui_iterator, false, false)
#define DBG_GUI_I LOG_STREAM_INDENT(debug, gui2::log_gui_iterator)
#define LOG_GUI_I LOG_STREAM_INDENT(info, gui2::log_gui_iterator)
#define WRN_GUI_I LOG_STREAM_INDENT(warn, gui2::log_gui_iterator)
Expand Down
2 changes: 1 addition & 1 deletion src/gui/dialogs/message.cpp
Expand Up @@ -200,7 +200,7 @@ void show_error_message(CVideo& video,
const std::string& message,
bool message_use_markup)
{
LOG_STREAM(err, lg::general) << message << '\n';
LOG_STREAM(err, lg::general()) << message << '\n';
show_message(video,
_("Error"),
message,
Expand Down
2 changes: 1 addition & 1 deletion src/gui/dialogs/transient_message.cpp
Expand Up @@ -73,7 +73,7 @@ void show_transient_error_message(CVideo& video,
const std::string& image,
const bool message_use_markup)
{
LOG_STREAM(err, lg::general) << message << '\n';
LOG_STREAM(err, lg::general()) << message << '\n';
show_transient_message(
video, _("Error"), message, image, message_use_markup);
}
Expand Down
8 changes: 4 additions & 4 deletions src/hotkey/command_executor.cpp
Expand Up @@ -38,10 +38,10 @@
#include <cassert>

static lg::log_domain log_config("config");
#define ERR_G LOG_STREAM(err, lg::general)
#define WRN_G LOG_STREAM(warn, lg::general)
#define LOG_G LOG_STREAM(info, lg::general)
#define DBG_G LOG_STREAM(debug, lg::general)
#define ERR_G LOG_STREAM(err, lg::general())
#define WRN_G LOG_STREAM(warn, lg::general())
#define LOG_G LOG_STREAM(info, lg::general())
#define DBG_G LOG_STREAM(debug, lg::general())
#define ERR_CF LOG_STREAM(err, log_config)

namespace {
Expand Down
6 changes: 3 additions & 3 deletions src/hotkey/hotkey_command.cpp
Expand Up @@ -24,9 +24,9 @@
#include "log.hpp"

static lg::log_domain log_config("config");
#define ERR_G LOG_STREAM(err, lg::general)
#define LOG_G LOG_STREAM(info, lg::general)
#define DBG_G LOG_STREAM(debug, lg::general)
#define ERR_G LOG_STREAM(err, lg::general())
#define LOG_G LOG_STREAM(info, lg::general())
#define DBG_G LOG_STREAM(debug, lg::general())
#define ERR_CF LOG_STREAM(err, log_config)


Expand Down
6 changes: 3 additions & 3 deletions src/hotkey/hotkey_item.cpp
Expand Up @@ -36,9 +36,9 @@


static lg::log_domain log_config("config");
#define ERR_G LOG_STREAM(err, lg::general)
#define LOG_G LOG_STREAM(info, lg::general)
#define DBG_G LOG_STREAM(debug, lg::general)
#define ERR_G LOG_STREAM(err, lg::general())
#define LOG_G LOG_STREAM(info, lg::general())
#define DBG_G LOG_STREAM(debug, lg::general())
#define ERR_CF LOG_STREAM(err, log_config)

namespace hotkey {
Expand Down
8 changes: 4 additions & 4 deletions src/language.cpp
Expand Up @@ -38,10 +38,10 @@ extern "C" int _putenv(const char*);
#include <cerrno>
#endif

#define DBG_G LOG_STREAM(debug, lg::general)
#define LOG_G LOG_STREAM(info, lg::general)
#define WRN_G LOG_STREAM(warn, lg::general)
#define ERR_G LOG_STREAM(err, lg::general)
#define DBG_G LOG_STREAM(debug, lg::general())
#define LOG_G LOG_STREAM(info, lg::general())
#define WRN_G LOG_STREAM(warn, lg::general())
#define ERR_G LOG_STREAM(err, lg::general())

namespace {
language_def current_language;
Expand Down
2 changes: 1 addition & 1 deletion src/loadscreen.cpp
Expand Up @@ -391,7 +391,7 @@ void loadscreen::increment_progress()

void loadscreen::dump_counters() const
{
if (lg::info.dont_log(log_loadscreen)) return;
if (lg::info().dont_log(log_loadscreen)) return;

std::ostringstream s;

Expand Down

0 comments on commit 8e58897

Please sign in to comment.