summaryrefslogtreecommitdiff
path: root/cpp/src
diff options
context:
space:
mode:
authorMichi Henning <michi@zeroc.com>2005-01-13 07:16:45 +0000
committerMichi Henning <michi@zeroc.com>2005-01-13 07:16:45 +0000
commit26d464a9e90ec682765772250e6634be625f42d1 (patch)
tree92a2f0370e758f28db8283b1442d4e511df61462 /cpp/src
parentFixed bug in the way the arguments were passed to a service. I'm not sure (diff)
downloadice-26d464a9e90ec682765772250e6634be625f42d1.tar.bz2
ice-26d464a9e90ec682765772250e6634be625f42d1.tar.xz
ice-26d464a9e90ec682765772250e6634be625f42d1.zip
Added print() operation to Ice::Logger and changed icepatch2server to use
logger instead of writing to stderr.
Diffstat (limited to 'cpp/src')
-rwxr-xr-xcpp/src/Ice/EventLoggerI.cpp13
-rwxr-xr-xcpp/src/Ice/EventLoggerI.h1
-rw-r--r--cpp/src/Ice/LoggerI.cpp15
-rw-r--r--cpp/src/Ice/LoggerI.h1
-rwxr-xr-xcpp/src/Ice/Service.cpp13
-rw-r--r--cpp/src/IcePatch2/Server.cpp26
6 files changed, 58 insertions, 11 deletions
diff --git a/cpp/src/Ice/EventLoggerI.cpp b/cpp/src/Ice/EventLoggerI.cpp
index 952184608c2..03ed4f96439 100755
--- a/cpp/src/Ice/EventLoggerI.cpp
+++ b/cpp/src/Ice/EventLoggerI.cpp
@@ -104,6 +104,19 @@ Ice::EventLoggerI::~EventLoggerI()
}
void
+Ice::EventLoggerI::print(const string& message)
+{
+ const char* str[1];
+ str[0] = message.c_str();
+ if(!ReportEvent(_source, EVENTLOG_INFORMATION_TYPE, 0, EVENT_LOGGER_MSG, NULL, 1, 0, str, NULL))
+ {
+ SyscallException ex(__FILE__, __LINE__);
+ ex.error = GetLastError();
+ throw ex;
+ }
+}
+
+void
Ice::EventLoggerI::trace(const string& category, const string& message)
{
string s;
diff --git a/cpp/src/Ice/EventLoggerI.h b/cpp/src/Ice/EventLoggerI.h
index 4e4791d3d05..ab4665ac40c 100755
--- a/cpp/src/Ice/EventLoggerI.h
+++ b/cpp/src/Ice/EventLoggerI.h
@@ -22,6 +22,7 @@ public:
EventLoggerI(const std::string&);
~EventLoggerI();
+ 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&);
diff --git a/cpp/src/Ice/LoggerI.cpp b/cpp/src/Ice/LoggerI.cpp
index aea6e956cc1..8cad1fe486e 100644
--- a/cpp/src/Ice/LoggerI.cpp
+++ b/cpp/src/Ice/LoggerI.cpp
@@ -26,6 +26,14 @@ Ice::LoggerI::LoggerI(const string& prefix, bool timestamp) :
}
void
+Ice::LoggerI::print(const string& message)
+{
+ IceUtil::Mutex::Lock sync(_globalMutex);
+
+ cerr << message << endl;
+}
+
+void
Ice::LoggerI::trace(const string& category, const string& message)
{
IceUtil::Mutex::Lock sync(_globalMutex);
@@ -35,7 +43,12 @@ Ice::LoggerI::trace(const string& category, const string& message)
{
s += IceUtil::Time::now().toString() + " ";
}
- s += _prefix + category + ": " + message + " ]";
+ s += _prefix;
+ if(!category.empty())
+ {
+ s += category + ": ";
+ }
+ s += message + " ]";
string::size_type idx = 0;
while((idx = s.find("\n", idx)) != string::npos)
diff --git a/cpp/src/Ice/LoggerI.h b/cpp/src/Ice/LoggerI.h
index 3b1c7e792cf..78703afd0c9 100644
--- a/cpp/src/Ice/LoggerI.h
+++ b/cpp/src/Ice/LoggerI.h
@@ -22,6 +22,7 @@ public:
LoggerI(const std::string&, bool);
+ 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&);
diff --git a/cpp/src/Ice/Service.cpp b/cpp/src/Ice/Service.cpp
index bb27af31740..d145d73df91 100755
--- a/cpp/src/Ice/Service.cpp
+++ b/cpp/src/Ice/Service.cpp
@@ -984,6 +984,19 @@ Ice::Service::trace(const string& msg)
}
void
+Ice::Service::print(const string& msg)
+{
+ if(_logger)
+ {
+ _logger->print(msg);
+ }
+ else
+ {
+ cerr << msg << endl;
+ }
+}
+
+void
Ice::Service::enableInterrupt()
{
_ctrlCHandler->setCallback(ctrlCHandlerCallback);
diff --git a/cpp/src/IcePatch2/Server.cpp b/cpp/src/IcePatch2/Server.cpp
index 52bb0559243..a06d8b1889e 100644
--- a/cpp/src/IcePatch2/Server.cpp
+++ b/cpp/src/IcePatch2/Server.cpp
@@ -58,6 +58,8 @@ protected:
private:
void usage(const std::string&);
+
+ LoggerPtr _logger;
};
};
@@ -69,6 +71,8 @@ IcePatch2::PatcherService::PatcherService()
bool
IcePatch2::PatcherService::start(int argc, char* argv[])
{
+ _logger = communicator()->getLogger();
+
string dataDir;
IceUtil::Options opts;
@@ -82,7 +86,7 @@ IcePatch2::PatcherService::start(int argc, char* argv[])
}
catch(const IceUtil::Options::BadOpt& e)
{
- cerr << e.reason << endl;
+ _logger->error(e.reason);
usage(argv[0]);
return false;
}
@@ -94,13 +98,13 @@ IcePatch2::PatcherService::start(int argc, char* argv[])
}
if(opts.isSet("v") || opts.isSet("version"))
{
- cout << ICE_STRING_VERSION << endl;
+ _logger->print(ICE_STRING_VERSION);
return false;
}
if(args.size() > 1)
{
- cerr << argv[0] << ": too many arguments" << endl;
+ _logger->error("too many arguments");
usage(argv[0]);
return false;
}
@@ -116,7 +120,7 @@ IcePatch2::PatcherService::start(int argc, char* argv[])
dataDir = properties->getProperty("IcePatch2.Directory");
if(dataDir.empty())
{
- cerr << argv[0] << ": no data directory specified" << endl;
+ _logger->error("no data directory specified");
usage(argv[0]);
return false;
}
@@ -141,19 +145,21 @@ IcePatch2::PatcherService::start(int argc, char* argv[])
}
catch(const string& ex)
{
- cerr << argv[0] << ": " << ex << endl;
+ _logger->error(ex);
return false;
}
catch(const char* ex)
{
- cerr << argv[0] << ": " << ex << endl;
+ _logger->error(ex);
return false;
}
const char* endpointsProperty = "IcePatch2.Endpoints";
if(properties->getProperty(endpointsProperty).empty())
{
- cerr << argv[0] << ": property `" << endpointsProperty << "' is not set" << endl;
+ ostringstream os;
+ os << "property `" << endpointsProperty << "' is not set";
+ _logger->error(os.str());
return false;
}
ObjectAdapterPtr adapter = communicator()->createObjectAdapter("IcePatch2");
@@ -237,8 +243,8 @@ IcePatch2::PatcherService::usage(const string& appName)
// --nochdir is intentionally not shown here. (See the comment in main().)
);
#endif
- cerr << "Usage: " << appName << " [options] [DIR]" << endl;
- cerr << options << endl;
+ _logger->print("Usage: " + appName + " [options] [DIR]");
+ _logger->print(options);
}
int
@@ -278,7 +284,7 @@ main(int argc, char* argv[])
try
{
status = svc.main(argc + 1, v);
- }
+ u
catch(...)
{
// Ignore exceptions -- the only thing left to do is to free memory.