Author: shuston
Date: Wed Oct 22 16:59:58 2008
New Revision: 707228

URL: http://svn.apache.org/viewvc?rev=707228&view=rev
Log:
Add skeleton Windows logging options

Added:
    incubator/qpid/trunk/qpid/cpp/src/qpid/log/windows/
    incubator/qpid/trunk/qpid/cpp/src/qpid/log/windows/SinkOptions.cpp
    incubator/qpid/trunk/qpid/cpp/src/qpid/log/windows/SinkOptions.h

Added: incubator/qpid/trunk/qpid/cpp/src/qpid/log/windows/SinkOptions.cpp
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/log/windows/SinkOptions.cpp?rev=707228&view=auto
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/log/windows/SinkOptions.cpp (added)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/log/windows/SinkOptions.cpp Wed Oct 
22 16:59:58 2008
@@ -0,0 +1,115 @@
+/*
+ *
+ * Copyright (c) 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include "SinkOptions.h"
+#include "qpid/log/SinkOptions.h"
+#include "qpid/log/Logger.h"
+#include "qpid/log/OstreamOutput.h"
+#include "qpid/memory.h"
+#include "qpid/Exception.h"
+#include <iostream>
+#include <map>
+#include <string>
+
+using std::string;
+using qpid::Exception;
+
+namespace qpid {
+namespace log {
+namespace windows {
+
+class EventLogOutput : public qpid::log::Logger::Output {
+public:
+    EventLogOutput(const std::string& logName)
+    {
+    }
+
+    virtual ~EventLogOutput() {
+    }
+    
+    virtual void log(const Statement& s, const std::string& m)
+    {
+    }
+
+private:    
+};
+
+SinkOptions::SinkOptions(const std::string& argv0)
+    : qpid::log::SinkOptions(),
+      logToStderr(true),
+      logToStdout(false),
+      logToEventLog(false)
+{
+    addOptions()
+      ("log-to-stderr", optValue(logToStderr, "yes|no"), "Send logging output 
to stderr")
+      ("log-to-stdout", optValue(logToStdout, "yes|no"), "Send logging output 
to stdout")
+      ("log-to-file", optValue(logFile, "FILE"), "Send log output to FILE.")
+      ("log-to-eventlog", optValue(logToEventLog, "yes|no"), "Send logging 
output to event log;\n\tcustomize using --syslog-name and --syslog-facility")
+      ("syslog-name", optValue(syslogName, "NAME"), "Name to use in syslog 
messages")
+      ("syslog-facility", optValue(syslogFacility,"LOG_XXX"), "Facility to use 
in syslog messages")
+      ;
+
+}
+
+qpid::log::SinkOptions& SinkOptions::operator=(const qpid::log::SinkOptions& 
rhs) {
+    const SinkOptions *prhs = dynamic_cast<const SinkOptions*>(&rhs);
+    if (this != prhs) {
+        logToStderr = prhs->logToStderr;
+        logToStdout = prhs->logToStdout;
+        logToEventLog = prhs->logToEventLog;
+        logFile = prhs->logFile;
+        syslogName = prhs->syslogName;
+        syslogFacility.value = prhs->syslogFacility.value;
+    }
+    return *this;
+}
+
+void SinkOptions::detached(void) {
+    if (logToStderr && !logToStdout && !logToEventLog) {
+        logToStderr = false;
+        logToEventLog = true;
+    }
+}
+
+// The Logger acting on these options calls setup() to request any
+// Sinks be set up and fed back to the logger.
+void SinkOptions::setup(qpid::log::Logger *logger) {
+    if (logToStderr)
+        logger->output(make_auto_ptr<qpid::log::Logger::Output>
+                         (new qpid::log::OstreamOutput(std::clog)));
+    if (logToStdout)
+        logger->output(make_auto_ptr<qpid::log::Logger::Output>
+                         (new qpid::log::OstreamOutput(std::cout)));
+
+    if (logFile.length() > 0)
+        logger->output(make_auto_ptr<qpid::log::Logger::Output>
+                         (new qpid::log::OstreamOutput(logFile)));
+
+    if (logToEventLog)
+        logger->output(make_auto_ptr<qpid::log::Logger::Output>
+                         (new EventLogOutput(syslogName, syslogFacility)));
+
+}
+
+} // namespace windows
+
+SinkOptions* SinkOptions::create(const std::string& argv0) {
+    return new qpid::log::windows::SinkOptions (argv0);
+}
+
+}} // namespace qpid::log

Added: incubator/qpid/trunk/qpid/cpp/src/qpid/log/windows/SinkOptions.h
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/log/windows/SinkOptions.h?rev=707228&view=auto
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/log/windows/SinkOptions.h (added)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/log/windows/SinkOptions.h Wed Oct 22 
16:59:58 2008
@@ -0,0 +1,53 @@
+#ifndef QPID_LOG_WINDOWS_SINKOPTIONS_H
+#define QPID_LOG_WINDOWS_SINKOPTIONS_H
+
+/*
+ *
+ * Copyright (c) 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include "qpid/log/SinkOptions.h"
+#include <string>
+
+namespace qpid {
+namespace log {
+namespace windows {
+
+struct SinkOptions : public qpid::log::SinkOptions {
+    SinkOptions(const std::string& argv0);
+    virtual ~SinkOptions() {}
+
+    virtual qpid::log::SinkOptions& operator=(const qpid::log::SinkOptions& 
rhs);
+
+    // This allows the caller to indicate that there's no normal outputs
+    // available. For example, when running as a service. In these cases, the
+    // platform's "syslog"-type output should replace the default stderr
+    // unless some other sink has been selected.
+    virtual void detached(void);
+
+    // The Logger acting on these options calls setup() to request any
+    // Sinks be set up and fed back to the logger.
+    virtual void setup(qpid::log::Logger *logger);
+
+    bool logToStderr;
+    bool logToStdout;
+    bool logToEventLog;
+    std::string logFile;
+};
+
+}}} // namespace qpid::log::windows
+
+#endif  /*!QPID_LOG_WINDOWS_SINKOPTIONS_H*/


Reply via email to