A try at timestamping log messages (in the campaign server for now).

This commit is contained in:
Guillaume Melquiond 2005-05-01 08:57:54 +00:00
parent 2460b983e1
commit 914823feef
3 changed files with 18 additions and 4 deletions

View file

@ -1,5 +1,6 @@
#include "config.hpp"
#include "filesystem.hpp"
#include "log.hpp"
#include "network.hpp"
#include "publish_campaign.hpp"
#include "util.hpp"
@ -10,6 +11,8 @@
#include <iostream>
#define LOG_CS lg::err(lg::network, false)
namespace {
config construct_message(const std::string& msg)
@ -71,7 +74,7 @@ void campaign_server::run()
network::connection sock = network::accept_connection();
if(sock) {
std::cerr << "received connection from " << network::ip_address(sock) << "\n";
LOG_CS << "received connection from " << network::ip_address(sock) << "\n";
}
config data;
@ -166,13 +169,13 @@ void campaign_server::run()
}
} catch(network::error& e) {
if(!e.socket) {
std::cerr << "fatal network error\n";
LOG_CS << "fatal network error\n";
break;
} else {
e.disconnect();
}
} catch(config::error& e) {
std::cerr << "error in receiving data...\n";
LOG_CS << "error in receiving data...\n";
}
SDL_Delay(500);
@ -183,6 +186,7 @@ void campaign_server::run()
int main(int argc, char** argv)
{
lg::timestamps(true);
try {
campaign_server("server.cfg").run();
} catch(config::error& e) {

View file

@ -19,6 +19,7 @@
#include "log.hpp"
#include <algorithm>
#include <ctime>
#include <iostream>
#include <sstream>
#include <vector>
@ -42,9 +43,12 @@ public:
static std::vector< logd > log_domains;
static std::ostream null_ostream(new null_streambuf);
static int indent = 0;
static bool timestamp = false;
namespace lg {
void timestamps(bool t) { timestamp = t; }
logger err("error", 0), warn("warning", 1), info("info", 2);
log_domain general("general"), ai("ai"), config("config"), display("display"), engine("engine"),
network("network"), filesystem("filesystem");
@ -86,8 +90,12 @@ std::ostream &logger::operator()(log_domain const &domain, bool show_names) cons
if (severity_ > d.severity_)
return null_ostream;
else {
if (timestamp) {
time_t t = time(NULL);
std::cerr << ctime(&t) << ' ';
}
if (show_names)
std::cerr << name_ << " " << d.name_ << ": ";
std::cerr << name_ << ' ' << d.name_ << ": ";
return std::cerr;
}
}

View file

@ -39,6 +39,8 @@ public:
bool dont_log(log_domain const &domain) const;
};
void timestamps(bool);
extern logger err, warn, info;
extern log_domain general, ai, config, display, engine, network, filesystem;