Commits

Danny Gratzer committed 1b40b90 Draft

Added ability to log more than just std::string types

  • Participants
  • Parent commits e6cbd6e

Comments (0)

Files changed (4)

examples/demo.cpp

-#include <string>
 #include "logger_creator.hpp"
 #include "logger.hpp"
 #include "handlers/cerr_handler.hpp"
 logger foo(){
 
   std_creator factory;
-  //factory.add_handler(std::make_shared<cerr_handler>());
-  //auto h = std::make_shared<file_handler>("log");
-  //factory.add_handler(h);
-  //factory.add_handler(std::make_shared<memory_handler>(10, h));
+  factory.add_handler(std::make_shared<cerr_handler>());
+  auto h = std::make_shared<file_handler>("log");
+  factory.add_handler(h);
+  factory.add_handler(std::make_shared<memory_handler>(10, h));
   factory.add_handler(std::make_shared<rolling_handler>("logs", 3, 2));
+  factory.spawn("temp")<<"Hello from a temporary"<<endl;
   return factory.spawn("test");
 }
 
   auto log = foo();
 
   for(int i = 0; i<25; ++i)
-    log<<std::to_string(i)<<endl;
+    log<<i<<endl;
 }
 	g++ -std=c++0x -c $(CFLAGS) -Isrc src/handlers/file_handler.cpp
 rotator.o : src/handlers/file_manipulators/rotator.cpp
 	g++ -std=c++0x -c $(CFLAGS) -Isrc src/handlers/file_manipulators/rotator.cpp
+
+clean-all:
+	rm -rf *.o
+	rm demo
+	rm -rf logs*
+	rm -rf log
 clean:
 	rm -rf *.o
 	rm demo
 clean-logs:
 	rm -rf logs*
 	rm -rf log
+
 #include "logger.hpp"
 #include <ctime>
+#include <sstream>
 using namespace al;
 
 al::end al::endl;
   return *this;
 }
 
+template<typename T>
+logger& logger::add_input(const T& t){
+  std::stringstream ss;
+  ss<<t;
+  return operator<<(ss.str());
+}
+
+logger& logger::operator<<(const int& input){
+  return add_input(input);
+}
+logger& logger::operator<<(const double& input){
+  return add_input(input);
+}
+logger& logger::operator<<(const char& input){
+  return add_input(input);
+}
+logger& logger::operator<<(const long& input){
+  return add_input(input);
+}
 logger& logger::operator<<(const std::string& input){
   message+=input;
   return *this;
        * Appends the string to the current message
        */
       virtual logger& operator<<(const std::string&);
+      /**
+       * Appends the long to the current message
+       */
+      virtual logger& operator<<(const int&);
+      /**
+       * Appends the long to the current message
+       */
+      virtual logger& operator<<(const long&);
+      /**
+       * Appends the double to the current message
+       */
+      virtual logger& operator<<(const double&);
+      /**
+       * Appends the char to the current message
+       */
+      virtual logger& operator<<(const char&);
+
+      /**
+       * Appends the T instance to the current message
+       * This uses a string stream to convert it.
+       * IT WILL FAIL FOR TYPES WITHOUT AN operator<<(stringstream&, T) of some type
+       */
 
       /**
        * Logs the current message
 
         std::string message;
         level current_level;
+
+        template<typename T>
+        logger& add_input(const T&);
   };
 }