Hi Matt,
Thanks. I have only one communicator. It is based on the demo/ice/bidirS
sample. My custom Logger is implemented on the Server side.
I went back to basics and modified the demo/ice/bidirS/Server.cpp sample
code and added my custom logger thus:
Code:
#include <CallbackI.h>
#include <Ice/Application.h>
using namespace std;
using namespace Demo;
class FilterLoggerI : public Ice::Logger
{
public:
FilterLoggerI(){};
virtual ~FilterLoggerI(){};
virtual void print(const std::string&);
virtual void trace(const std::string&, const std::string&);
virtual void warning(const std::string&);
virtual void error(const std::string&);
private:
};
typedef IceUtil::Handle<FilterLoggerI> FilterLoggerIPtr;
void FilterLoggerI::print(const std::string& msg)
{
std::cerr << "[info ] " << msg << std::endl;
}
void FilterLoggerI::trace(const std::string& category, const std::string& msg)
{
std::cerr << '[' << category << ']' << " " << msg << std::endl;
}
void FilterLoggerI::warning(const std::string& msg)
{
std::cerr << "[warning] " << msg << std::endl;
}
void FilterLoggerI::error(const std::string& msg)
{
std::cerr << "[error ] " << msg << std::endl;
}
class CallbackServer : public Ice::Application
{
public:
virtual int run(int, char*[]);
};
int
main(int argc, char* argv[])
{
CallbackServer app;
#if 0
return app.main(argc, argv, "config.server");
#else
// plug in the properties here for now ...
Ice::PropertiesPtr props = Ice::createProperties();
props->setProperty("Callback.Server.Endpoints","tcp -p 10000");
props->setProperty("Ice.ACM.Client","0");
props->setProperty("Ice.Warn.Connections","1");
Ice::InitializationData id;
id.properties = props;
// new Logger ...
id.logger = new FilterLoggerI;
return app.main(argc, argv,id);
#endif
}
int
CallbackServer::run(int argc, char* argv[])
{
Ice::ObjectAdapterPtr adapter = communicator()->createObjectAdapter("Callback.Server");
// **** This works ***** //
communicator()->getLogger()->trace("Monster", "Truck rally");
CallbackSenderIPtr sender = new CallbackSenderI(communicator());
adapter->add(sender, communicator()->stringToIdentity("sender"));
adapter->activate();
sender->start();
try
{
communicator()->waitForShutdown();
}
catch(...)
{
sender->destroy();
throw;
}
sender->destroy();
return EXIT_SUCCESS;
}
I ran the server and I see the trace "[Monster] Truck rally" on the console. When I terminate the client the low level trace messages do not pass through my logger. Just so that we're on the same page the messages I'm referring to are these low level server side ICE messages:
Code:
ConnectionI.cpp:2226: Ice::CloseConnectionException:
protocol error: connection closed
This is on Windows XP with Ice-3.2.0 and VS2005
Thanks, Vince