Author: carnold
Date: Mon Sep 24 23:29:20 2007
New Revision: 579087

URL: http://svn.apache.org/viewvc?rev=579087&view=rev
Log:
LOGCXX-18: Second iter, wchar_t, restore trivial.cpp from inadvertent change

Modified:
    logging/log4cxx/trunk/src/examples/cpp/trivial.cpp
    logging/log4cxx/trunk/src/main/cpp/messagebuffer.cpp
    logging/log4cxx/trunk/src/main/include/log4cxx/helpers/messagebuffer.h

Modified: logging/log4cxx/trunk/src/examples/cpp/trivial.cpp
URL: 
http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/examples/cpp/trivial.cpp?rev=579087&r1=579086&r2=579087&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/examples/cpp/trivial.cpp (original)
+++ logging/log4cxx/trunk/src/examples/cpp/trivial.cpp Mon Sep 24 23:29:20 2007
@@ -1,60 +1,53 @@
-#include <iostream>
-#include <pthread.h>
-#include <sstream>
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 <log4cxx/logstring.h>
+#include <stdlib.h>
 #include <log4cxx/logger.h>
-#include <log4cxx/propertyconfigurator.h>
+#include <log4cxx/basicconfigurator.h>
 #include <log4cxx/helpers/exception.h>
+#include <log4cxx/ndc.h>
+#include <locale.h>
 
-struct Data
-{
-    int count;
-};
+using namespace log4cxx;
+using namespace log4cxx::helpers;
 
-void* LogThread(void* args)
+int main()
 {
-    Data* d = (Data*)args;
-
-    // Build Logger Name
-    std::ostringstream temp;
-    temp << "TestLogger" << d->count;
-    std::string loggerName(temp.str());
-    std::cout << "getting logger = " << loggerName << std::endl;
-
-    log4cxx::LoggerPtr logger(log4cxx::Logger::getLogger(loggerName));
-
-    while(1)
+    setlocale(LC_ALL, "");
+    int result = EXIT_SUCCESS;
+    try
     {
-        logger->debug(loggerName);
-        logger->debug("This is a test of the emergency broadcast system.  This 
is only a test");
-        logger->debug("This is a test of the emergency broadcast system. This 
is only a test");
-        logger->debug("This is a test of the emergency broadcast system.  This 
is only a test");
-        logger->debug("This is a test of the emergency broadcast system.  This 
is only a test");
-        logger->debug("This is a test of the emergency broadcast system.  This 
is only a test");
-        logger->debug("This is a test of the emergency broadcast system.  This 
is only a test");
-        logger->debug("This is a test of the emergency broadcast system.  This 
is only a test");
+                BasicConfigurator::configure();
+                LoggerPtr rootLogger = Logger::getRootLogger();
 
-        usleep(5);
-    }
-
-    return 0;
-}
-
-int main(void)
-{
-    log4cxx::LoggerPtr logger(log4cxx::Logger::getRootLogger());
-    for(int count = 0; count < 10; count++)
-    {
-        Data* d = new Data();
-        d->count = count;
+                NDC::push("trivial context");
 
-        pthread_t newThread;
-        pthread_create(&newThread, NULL, &LogThread, d);
-        sleep(1);
-    }
-
-    std::string input;
-    std::cout << "Waiting for input to exit" << std::endl;
-    std::cin >> input;
+                LOG4CXX_DEBUG(rootLogger, "debug message");
+                LOG4CXX_INFO(rootLogger, "info message");
+                LOG4CXX_WARN(rootLogger, "warn message");
+                LOG4CXX_ERROR(rootLogger, "error message");
+                LOG4CXX_FATAL(rootLogger, "fatal message");
+
+                NDC::pop();
+        }
+        catch(std::exception&)
+        {
+                result = EXIT_FAILURE;
+        }
 
-    return 0;
+    return result;
 }

Modified: logging/log4cxx/trunk/src/main/cpp/messagebuffer.cpp
URL: 
http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/main/cpp/messagebuffer.cpp?rev=579087&r1=579086&r2=579087&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/main/cpp/messagebuffer.cpp (original)
+++ logging/log4cxx/trunk/src/main/cpp/messagebuffer.cpp Mon Sep 24 23:29:20 
2007
@@ -46,7 +46,7 @@
     return *this;
 }
         
-const std::string& CharMessageBuffer::str(const MessageBuffer&) const {
+const std::string& CharMessageBuffer::str(const CharMessageBuffer&) const {
     return buf;
 }
 
@@ -64,12 +64,12 @@
     delete wbuf;
 }
         
-WideMessageBuffer& MessageBuffer::operator+(const std::wstring& msg) {
+WideMessageBuffer& MessageBuffer::operator<<(const std::wstring& msg) {
    wbuf = new WideMessageBuffer(msg);
    return *wbuf;
 }
    
-WideMessageBuffer& MessageBuffer::operator+(const wchar_t* msg) {
+WideMessageBuffer& MessageBuffer::operator<<(const wchar_t* msg) {
    if (0 == msg) {
        wbuf = new WideMessageBuffer(L"null");
    } else {
@@ -78,7 +78,7 @@
    return *wbuf;
 }
 
-WideMessageBuffer& MessageBuffer::operator+(const wchar_t msg) {
+WideMessageBuffer& MessageBuffer::operator<<(const wchar_t msg) {
    wbuf = new WideMessageBuffer(msg);
    return *wbuf;
 }
@@ -129,6 +129,26 @@
 WideMessageBuffer& WideMessageBuffer::operator<<(const wchar_t msg) {
     buf.append(1, msg);
     return *this;
+}
+
+CharMessageBuffer& MessageBuffer::operator<<(const std::string& msg) {
+    return CharMessageBuffer::operator<<(msg);
+}
+
+CharMessageBuffer& MessageBuffer::operator<<(const char* msg) {
+    return CharMessageBuffer::operator<<(msg);
+}
+
+CharMessageBuffer& MessageBuffer::operator<<(const char msg) {
+    return CharMessageBuffer::operator<<(msg);
+}
+
+const std::string& MessageBuffer::str(const CharMessageBuffer& msg) const {
+    return CharMessageBuffer::str(msg);
+}
+
+std::string MessageBuffer::str(const std::ostream& msg) const {
+    return CharMessageBuffer::str(msg);
 }
 
 

Modified: logging/log4cxx/trunk/src/main/include/log4cxx/helpers/messagebuffer.h
URL: 
http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/main/include/log4cxx/helpers/messagebuffer.h?rev=579087&r1=579086&r2=579087&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/main/include/log4cxx/helpers/messagebuffer.h 
(original)
+++ logging/log4cxx/trunk/src/main/include/log4cxx/helpers/messagebuffer.h Mon 
Sep 24 23:29:20 2007
@@ -86,8 +86,22 @@
         WideMessageBuffer& operator<<(const wchar_t* msg);
         WideMessageBuffer& operator<<(const wchar_t msg);
 
+        CharMessageBuffer& operator<<(const std::string& msg);
+        CharMessageBuffer& operator<<(const char* msg);
+        CharMessageBuffer& operator<<(const char msg);
+
         const std::wstring& str(const WideMessageBuffer&) const;
         std::wstring str(const std::wostream&) const;
+        const std::string& str(const CharMessageBuffer&) const;
+        std::string str(const std::ostream&) const;
+
+        template<class T> 
+        std::ostream& operator<<(T arg) {
+           return CharMessageBuffer::operator<<(arg);
+        }
+
+
+
 
    private:
         WideMessageBuffer* wbuf;        


Reply via email to