| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- //
- // console_logger.cxx
- // logging
- //
- // Created by Sam Jaffe on 4/1/19.
- //
- #include <iostream>
- #include "expect/expect.hpp"
- #include "resource_factory/prototype_factory.hpp"
- #include "logger/detail/appender.h"
- #include "logger/log_manager.h"
- #include "logger/properties.h"
- using namespace logging;
- class console_appender : public appender {
- public:
- static std::shared_ptr<appender> create(properties const& props);
-
- explicit console_appender(std::ostream& os);
-
- void write(std::string const & msg) override;
-
- void flush() override;
- private:
- std::ostream& out_;
- };
- std::shared_ptr<appender> console_appender::create(properties const& props) {
- const std::string target = props["target"];
- if (target == "SYSTEM_OUT") {
- return std::make_shared<console_appender>(std::cout);
- } else if (target == "SYSTEM_ERR") {
- return std::make_shared<console_appender>(std::cerr);
- } else {
- throw std::logic_error{target + " is not a valid console"};
- }
- }
- console_appender::console_appender(std::ostream& os) : out_(os) {}
- void console_appender::write(std::string const & msg) {
- out_ << msg;
- }
- void console_appender::flush() {
- out_.flush();
- }
- namespace {
- bool _ = appenders::instance().bind("Console", console_appender::create);
- }
|