file_logger.cpp 952 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. //
  2. // file_logger.cpp
  3. // logger
  4. //
  5. // Created by Sam Jaffe on 10/2/15.
  6. //
  7. //
  8. #include "logger.hpp"
  9. #include "default_logger_binding.hpp"
  10. #include <fstream>
  11. namespace logging {
  12. class file_logger : public logger_impl {
  13. public:
  14. static std::unique_ptr<logger_impl> create(logging::properties const&);
  15. file_logger(const std::string& fname);
  16. void write(log_level level, std::string const& msg) override;
  17. void flush() override;
  18. private:
  19. std::ofstream out_;
  20. };
  21. std::unique_ptr<logger_impl> file_logger::create(properties const&) {
  22. return std::unique_ptr<logger_impl>(); // TODO
  23. }
  24. file_logger::file_logger(const std::string& fname)
  25. : out_(fname) {}
  26. void file_logger::write(log_level level, std::string const& msg) {
  27. out_ << msg;
  28. }
  29. void file_logger::flush() {
  30. out_.flush();
  31. }
  32. namespace {
  33. bool _ = default_logger_impl::register_impl("File", file_logger::create);
  34. }
  35. }