aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--server/common/log.hpp25
-rw-r--r--server/main/main.cpp3
-rw-r--r--server/main/server.cpp8
-rw-r--r--server/main/session.cpp4
-rw-r--r--server/main/session_manager.cpp2
-rw-r--r--server/main/settings.hpp5
6 files changed, 28 insertions, 19 deletions
diff --git a/server/common/log.hpp b/server/common/log.hpp
index 52f96c1..505faed 100644
--- a/server/common/log.hpp
+++ b/server/common/log.hpp
@@ -6,10 +6,11 @@
#pragma once
#include <boost/date_time/posix_time/posix_time.hpp>
-#include <boost/format.hpp>
#include <boost/system/error_code.hpp>
#include <ctime>
+#include <exception>
+#include <format>
#include <iomanip>
#include <iostream>
#include <sstream>
@@ -22,8 +23,10 @@ namespace math::server::log {
namespace details {
-inline std::thread::id get_tid() {
- return std::this_thread::get_id();
+inline std::string get_tid() {
+ std::ostringstream oss;
+ oss << std::this_thread::get_id();
+ return oss.str();
}
inline std::string get_timestamp() {
@@ -35,23 +38,27 @@ inline std::string get_timestamp() {
}
inline void log(const std::string& msg) {
- std::clog << get_timestamp() << " | " << get_tid() << " | " << msg << '\n';
+ std::clog << std::format("{} | {} | {}\n", get_timestamp(), get_tid(), msg);
}
} // namespace details
template <typename... Args>
-inline void log(std::string_view fmt, Args&&... args) {
- details::log(boost::str((boost::format(fmt.data()) % ... % args)));
+inline void log(std::format_string<Args...> fmt, Args&&... args) {
+ details::log(std::format(fmt, std::forward<Args>(args)...));
}
template <typename... Args>
-inline void error(std::string_view fmt, Args&&... args) {
- details::log(boost::str((boost::format(fmt.data()) % ... % args)));
+inline void error(std::format_string<Args...> fmt, Args&&... args) {
+ details::log(std::format(fmt, std::forward<Args>(args)...));
}
inline void error(const boost::system::error_code& ec) {
- details::log(ec.message());
+ log("{}", ec.message());
+}
+
+inline void error(const std::exception& e) {
+ log("{}", e.what());
}
} // namespace math::server::log
diff --git a/server/main/main.cpp b/server/main/main.cpp
index b44f131..f9b803d 100644
--- a/server/main/main.cpp
+++ b/server/main/main.cpp
@@ -9,6 +9,7 @@
#include <boost/program_options.hpp>
#include <exception>
+#include <format>
#include <iostream>
int main(int argc, char* argv[]) {
@@ -29,7 +30,7 @@ int main(int argc, char* argv[]) {
return 1;
}
} catch (const std::exception& e) {
- std::cerr << "An error occured: " << e.what() << "\n";
+ std::cerr << std::format("An error occured: {}\n", e.what());
return 1;
} catch (...) {
std::cerr << "An unknown error occured\n";
diff --git a/server/main/server.cpp b/server/main/server.cpp
index 4c0ab83..0f3fdc8 100644
--- a/server/main/server.cpp
+++ b/server/main/server.cpp
@@ -78,16 +78,16 @@ void Server::wait_for_signal() {
void Server::handle_signal(const boost::system::error_code& ec, int signo) {
if (ec) {
- log::error("%1%: %2%", __func__, ec.message());
+ log::error("{}: {}", __func__, ec.message());
}
- log::log("Caught signal %1%", signo);
+ log::log("Caught signal {}", signo);
try {
m_acceptor.close();
m_session_mgr.stop_all();
} catch (const std::exception& e) {
- log::error(e.what());
+ log::error(e);
}
}
@@ -101,7 +101,7 @@ void Server::accept() {
void Server::handle_accept(SessionPtr session, const boost::system::error_code& ec) {
if (ec) {
- log::error("%1%: %2%", __func__, ec.message());
+ log::error("{}: {}", __func__, ec.message());
return;
}
diff --git a/server/main/session.cpp b/server/main/session.cpp
index b4b9fc5..c51fcd6 100644
--- a/server/main/session.cpp
+++ b/server/main/session.cpp
@@ -82,7 +82,7 @@ void Session::read() {
void Session::handle_read(const boost::system::error_code& ec, std::size_t bytes) {
if (ec) {
- log::error("%1%: %2%", __func__, ec.message());
+ log::error("{}: {}", __func__, ec.message());
m_session_mgr.stop(shared_from_this());
return;
}
@@ -117,7 +117,7 @@ void Session::write(const std::string& output) {
void Session::handle_write(const boost::system::error_code& ec, std::size_t) {
if (ec) {
- log::error("%1%: %2%", __func__, ec.message());
+ log::error("{}: {}", __func__, ec.message());
m_session_mgr.stop(shared_from_this());
return;
}
diff --git a/server/main/session_manager.cpp b/server/main/session_manager.cpp
index 0b6e7cf..59f09fd 100644
--- a/server/main/session_manager.cpp
+++ b/server/main/session_manager.cpp
@@ -34,7 +34,7 @@ void SessionManager::stop(const SessionPtr& session) {
void SessionManager::stop_all() {
std::lock_guard<std::mutex> lck{m_mtx};
- log::log("Closing the remaining %1% session(s)...", m_sessions.size());
+ log::log("Closing the remaining {} session(s)...", m_sessions.size());
for (const auto& session : m_sessions) {
session->stop();
}
diff --git a/server/main/settings.hpp b/server/main/settings.hpp
index b6c5b86..0c40ac3 100644
--- a/server/main/settings.hpp
+++ b/server/main/settings.hpp
@@ -10,6 +10,7 @@
#include <cstddef>
#include <exception>
#include <filesystem>
+#include <format>
#include <iostream>
#include <string>
#include <thread>
@@ -72,7 +73,7 @@ public:
}
void usage_error(const std::exception& e) const {
- std::cerr << "usage error: " << e.what() << '\n';
+ std::cerr << std::format("usage error: {}\n", e.what());
std::cerr << *this;
}
@@ -88,7 +89,7 @@ private:
Settings m_settings;
friend std::ostream& operator<<(std::ostream& os, const SettingsParser& parser) {
- os << "usage: " << parser.m_prog_name << ' ' << get_short_description() << '\n';
+ os << std::format("usage: {} {}\n", parser.m_prog_name, get_short_description());
os << parser.m_visible;
return os;
}