Skip to content

Commit

Permalink
campaignd: Log messages to a new log domain of our own
Browse files Browse the repository at this point in the history
Until now, campaignd logged its diagnostics to the network log domain
with the show_names parameter (of logger::operator()()) set to false so
as to avoid showing the log level or domain names in stderr. There are
two issues with this approach:

 * In order to tell the difference between informational and error
   messages, the messages themselves need to include a severity label in
   some form, which defeats half the point of using our standard logging
   facilities (though not the other half, which is having timestamps).
 * In the event that messages from other domains appear in stderr (which
   can only happen if their severity is 'warning' or more at this time,
   since campaignd doesn't change the default severity configuration),
   the log could become a jumbled mess.

Note that wesnothd (which produces a larger volume of diagnostics all
the time) does already use a log domain of its own with no overidden
show_names option.

Giving campaignd its own log domain should allow us to add more optional
diagnostics later if needed, and right now it allows us to do away with
the unwieldy severity labels in the log messages themselves in favor of
choosing the right logger in the invocation -- although this last point
is beyond the scope of this introductory commit.

This commit keeps our previous logging macro, LOG_CS, just replacing the
log domain and severity (info instead of err) and dropping the
overridden show_names value. Later I'll take care of choosing more
relevant severities for different messages. For now, we do like wesnothd
and select the info severity as the default during initialization so the
messages can still display.
  • Loading branch information
irydacea committed Jun 29, 2014
1 parent 37a8e25 commit 8f5dc70
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/campaign_server/campaign_server.cpp
Expand Up @@ -48,8 +48,11 @@
#include <errno.h>
#endif

static lg::log_domain log_network("network");
#define LOG_CS if(lg::err.dont_log(log_network)) ; else lg::err(log_network, false)
static lg::log_domain log_campaignd("campaignd");
#define DBG_CS LOG_STREAM(debug, log_campaignd)
#define LOG_CS LOG_STREAM(info, log_campaignd)
#define WRN_CS LOG_STREAM(warn, log_campaignd)
#define ERR_CS LOG_STREAM(err, log_campaignd)

//compatibility code for MS compilers
#ifndef SIGHUP
Expand Down Expand Up @@ -710,6 +713,7 @@ int main(int argc, char**argv)
{
game_config::path = get_cwd();

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

try {
Expand Down

0 comments on commit 8f5dc70

Please sign in to comment.