Commit 9a0af839 authored by atj's avatar atj
Browse files

Make logger a bit more robust to socket issues hopefully

parent ac2404c7
Loading
Loading
Loading
Loading
Loading
+18 −5
Original line number Diff line number Diff line
@@ -13,13 +13,26 @@ BOOST_LOG_GLOBAL_LOGGER_INIT(global_log, src::logger) {

namespace logger {
    void write(const std::string &message) {
        try {
            src::logger &lg = global_log::get();
            BOOST_LOG(lg) << message;
        } catch(...) {
            std::cerr<<"Error writing message: "<< message << std::endl;
        }
    }

    void write(const tcp::socket &socket, const std::string &message) {
        try {
            src::logger &lg = global_log::get();
        const std::string connection_string = boost::lexical_cast<std::string>(socket.remote_endpoint());
            std::string connection_string;
            if (socket.is_open()) {
                connection_string = boost::lexical_cast<std::string>(socket.remote_endpoint());
            } else {
                connection_string = "socket-closed";
            }
            BOOST_LOG(lg) << " [" << connection_string << "] : " << message;
        } catch(...) {
            std::cerr<<"Error writing message: "<< message << std::endl;
        }
    }
}
 No newline at end of file