logging.h 583 B

12345678910111213141516171819202122232425262728293031323334
  1. #ifndef __LOGGING_H
  2. #define __LOGGING_H
  3. #include <iostream>
  4. #include <fstream>
  5. namespace logger {
  6. struct Sink {
  7. std::string filename;
  8. std::string msg;
  9. Sink(const std::string& name) : filename(name) {}
  10. ~Sink() {
  11. try {
  12. std::ofstream out;
  13. out.exceptions(std::ofstream::failbit|std::ofstream::badbit);
  14. out.open(filename, std::ios::out|std::ios::app);
  15. out << msg;
  16. out.close();
  17. } catch(...) {
  18. }
  19. }
  20. void operator<<(const std::string& t) {
  21. msg += t;
  22. }
  23. };
  24. }
  25. #endif