Skip to content

Commit

Permalink
add "write_to" parameter to wml_message
Browse files Browse the repository at this point in the history
"write_to" lets the wmldev specify to where the message should be
written. Defaults to the previous behaviour.

The intention is for example that one might want to give a summary  as a
chat message and a very detailed information in the stderr file.
  • Loading branch information
gfgtdf committed May 19, 2014
1 parent aaff4bd commit 3dbc78f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
3 changes: 2 additions & 1 deletion src/game_events/action_wml.cpp
Expand Up @@ -593,8 +593,9 @@ void handle_wml_log_message(const config& cfg)
{
const std::string& logger = cfg["logger"];
const std::string& msg = cfg["message"];
const std::string& type = cfg["write_to"];

put_wml_message(logger,msg);
put_wml_message(logger,msg,type);
}


Expand Down
27 changes: 18 additions & 9 deletions src/game_events/pump.cpp
Expand Up @@ -373,6 +373,19 @@ namespace { // Support functions
show_wml_messages(wml_messages_stream, caption, false);
}

void put_wml_message(lg::logger& logger, const std::string& prefix, const std::string& message, const std::string& type)
{
if (type != "chat")
{
logger(log_wml) << message << "\n";
}
if (type != "console")
{
wml_messages_stream << prefix << message << "\n";
}
}


} // end anonymous namespace (support functions)


Expand Down Expand Up @@ -401,20 +414,16 @@ context::scoped::~scoped()
* Helper function which determines whether a wml_message text can
* really be pushed into the wml_messages_stream, and does it.
*/
void put_wml_message(const std::string& logger, const std::string& message)
void put_wml_message(const std::string& logger, const std::string& message, const std::string& type)
{
if (logger == "err" || logger == "error") {
ERR_WML << message << "\n";
wml_messages_stream << _("Error: ") << message << "\n";
put_wml_message(lg::err, _("Error: "), message, type );
} else if (logger == "warn" || logger == "wrn" || logger == "warning") {
WRN_WML << message << "\n";
wml_messages_stream << _("Warning: ") << message << "\n";
put_wml_message(lg::warn, _("Warning: "), message, type );
} else if ((logger == "debug" || logger == "dbg") && !lg::debug.dont_log(log_wml)) {
DBG_WML << message << "\n";
wml_messages_stream << _("Debug: ") << message << "\n";
put_wml_message(lg::debug, _("Debug: "), message, type );
} else if (!lg::info.dont_log(log_wml)) {
LOG_WML << message << "\n";
wml_messages_stream << _("Info: ") << message << "\n";
put_wml_message(lg::info, _("Info: "), message, type );
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/game_events/pump.hpp
Expand Up @@ -97,7 +97,8 @@ namespace game_events

/// Helper function which determines whether a wml_message text can
/// really be pushed into the wml_messages_stream, and does it.
void put_wml_message(const std::string& logger, const std::string& message);
/// @param type: "console" for logging into console, "chat" for logging into chat, every other value for loggign into both.
void put_wml_message(const std::string& logger, const std::string& message, const std::string& type = "both");

/**
* Directly runs the lua command(s) @a lua_code
Expand Down

0 comments on commit 3dbc78f

Please sign in to comment.