summaryrefslogtreecommitdiff
path: root/cpp
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
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')
-rw-r--r--cpp/demo/Ice/MFC/server/LogI.cpp15
-rw-r--r--cpp/demo/Ice/MFC/server/LogI.h53
-rwxr-xr-xcpp/include/Ice/Service.h5
-rw-r--r--cpp/slice/Ice/Logger.ice14
-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
10 files changed, 116 insertions, 40 deletions
diff --git a/cpp/demo/Ice/MFC/server/LogI.cpp b/cpp/demo/Ice/MFC/server/LogI.cpp
index f8aa79884f1..ee8b7a80566 100644
--- a/cpp/demo/Ice/MFC/server/LogI.cpp
+++ b/cpp/demo/Ice/MFC/server/LogI.cpp
@@ -18,6 +18,21 @@ LogI::LogI() :
}
void
+LogI::print(const string& msg)
+{
+ string s = msg;
+
+ string::size_type idx = 0;
+ while((idx = s.find("\n", idx)) != string::npos)
+ {
+ s.replace(idx, 1, "\r\n ");
+ idx += 3;
+ }
+
+ message(s);
+}
+
+void
LogI::trace(const string& category, const string& msg)
{
string s = "[ " + category + ": " + msg + " ]";
diff --git a/cpp/demo/Ice/MFC/server/LogI.h b/cpp/demo/Ice/MFC/server/LogI.h
index f6d3aae5138..22d8b66049b 100644
--- a/cpp/demo/Ice/MFC/server/LogI.h
+++ b/cpp/demo/Ice/MFC/server/LogI.h
@@ -7,29 +7,30 @@
//
// **********************************************************************
-
-#ifndef LOG_I_H
-#define LOG_I_H
-
-class LogI : public Ice::Logger
-{
-public:
-
- LogI();
-
- virtual void trace(const std::string&, const std::string&);
- virtual void warning(const std::string&);
- virtual void error(const std::string&);
-
- void message(const std::string&);
- void setControl(CEdit*);
-
-private:
-
- std::string _buffer;
- CEdit* _log;
-};
-
-typedef IceUtil::Handle<LogI> LogIPtr;
-
-#endif
+
+#ifndef LOG_I_H
+#define LOG_I_H
+
+class LogI : public Ice::Logger
+{
+public:
+
+ LogI();
+
+ 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&);
+
+ void message(const std::string&);
+ void setControl(CEdit*);
+
+private:
+
+ std::string _buffer;
+ CEdit* _log;
+};
+
+typedef IceUtil::Handle<LogI> LogIPtr;
+
+#endif
diff --git a/cpp/include/Ice/Service.h b/cpp/include/Ice/Service.h
index 6ddac7e8e87..6623b92f674 100755
--- a/cpp/include/Ice/Service.h
+++ b/cpp/include/Ice/Service.h
@@ -196,6 +196,11 @@ protected:
virtual void trace(const std::string&);
//
+ // Log a literal message.
+ //
+ virtual void print(const std::string&);
+
+ //
// Enable the CtrlCHandler to invoke interrupt() when a signal occurs.
//
void enableInterrupt();
diff --git a/cpp/slice/Ice/Logger.ice b/cpp/slice/Ice/Logger.ice
index 20f58257b0f..5a2bde33478 100644
--- a/cpp/slice/Ice/Logger.ice
+++ b/cpp/slice/Ice/Logger.ice
@@ -23,7 +23,15 @@ local interface Logger
{
/**
*
- * Log trace messages.
+ * Print a message. The message is printed literally, without
+ * any decorations such as executable name or time stamp.
+ *
+ **/
+ void print(string message);
+
+ /**
+ *
+ * Log a trace message.
*
* @param category The trace category.
*
@@ -34,7 +42,7 @@ local interface Logger
/**
*
- * Log warning messages.
+ * Log a warning message.
*
* @param message The warning message to log.
*
@@ -45,7 +53,7 @@ local interface Logger
/**
*
- * Log error messages.
+ * Log an error message.
*
* @param message The error message to log.
*
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.