Skip to content

Commit 6e6acba

Browse files
committed
Updated to c++ 23.
1 parent 6db3bd3 commit 6e6acba

File tree

2 files changed

+26
-45
lines changed

2 files changed

+26
-45
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.5)
22

33
project(auto_sdr LANGUAGES CXX)
44

5-
set(CMAKE_CXX_STANDARD 17)
5+
set(CMAKE_CXX_STANDARD 23)
66
set(CMAKE_CXX_STANDARD_REQUIRED ON)
77

88
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Wall -Wextra -Wpedantic -Wno-missing-braces")

sources/logger.h

Lines changed: 25 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -13,63 +13,48 @@ constexpr auto YELLOW = "\033[0;93m";
1313
constexpr auto BLUE = "\033[0;94m";
1414
constexpr auto NC = "\033[0m";
1515

16+
template <typename... Args>
17+
using format_string = fmt::format_string<Args...>;
18+
1619
class Logger {
1720
public:
1821
static void configure(
1922
const spdlog::level::level_enum logLevelConsole, const spdlog::level::level_enum logLevelFile, const std::string& logFile, int fileSize, int filesCount, bool isColorLogEnabled);
2023

2124
template <typename... Args>
22-
static void trace(const char* label, const char* fmt, const Args&... args) {
23-
char buf[LOGGER_BUFFER_SIZE];
24-
std::memset(buf, 0, LOGGER_BUFFER_SIZE);
25-
strcat(buf, "[{:12}] ");
26-
strcat(buf, fmt);
27-
Logger::_logger->trace(buf, label, args...);
25+
static void trace(const char* label, fmt::format_string<Args...> fmt, Args&&... args) {
26+
auto msg = fmt::format(fmt, std::forward<Args>(args)...);
27+
Logger::_logger->trace("[{:12}] {}", label, msg);
2828
}
2929

3030
template <typename... Args>
31-
static void debug(const char* label, const char* fmt, const Args&... args) {
32-
char buf[LOGGER_BUFFER_SIZE];
33-
std::memset(buf, 0, LOGGER_BUFFER_SIZE);
34-
strcat(buf, "[{:12}] ");
35-
strcat(buf, fmt);
36-
Logger::_logger->debug(buf, label, args...);
31+
static void debug(const char* label, fmt::format_string<Args...> fmt, Args&&... args) {
32+
auto msg = fmt::format(fmt, std::forward<Args>(args)...);
33+
Logger::_logger->debug("[{:12}] {}", label, msg);
3734
}
3835

3936
template <typename... Args>
40-
static void info(const char* label, const char* fmt, const Args&... args) {
41-
char buf[LOGGER_BUFFER_SIZE];
42-
std::memset(buf, 0, LOGGER_BUFFER_SIZE);
43-
strcat(buf, "[{:12}] ");
44-
strcat(buf, fmt);
45-
Logger::_logger->info(buf, label, args...);
37+
static void info(const char* label, fmt::format_string<Args...> fmt, Args&&... args) {
38+
auto msg = fmt::format(fmt, std::forward<Args>(args)...);
39+
Logger::_logger->info("[{:12}] {}", label, msg);
4640
}
4741

4842
template <typename... Args>
49-
static void warn(const char* label, const char* fmt, const Args&... args) {
50-
char buf[LOGGER_BUFFER_SIZE];
51-
std::memset(buf, 0, LOGGER_BUFFER_SIZE);
52-
strcat(buf, "[{:12}] ");
53-
strcat(buf, fmt);
54-
Logger::_logger->warn(buf, label, args...);
43+
static void warn(const char* label, fmt::format_string<Args...> fmt, Args&&... args) {
44+
auto msg = fmt::format(fmt, std::forward<Args>(args)...);
45+
Logger::_logger->warn("[{:12}] {}", label, msg);
5546
}
5647

5748
template <typename... Args>
58-
static void error(const char* label, const char* fmt, const Args&... args) {
59-
char buf[LOGGER_BUFFER_SIZE];
60-
std::memset(buf, 0, LOGGER_BUFFER_SIZE);
61-
strcat(buf, "[{:12}] ");
62-
strcat(buf, fmt);
63-
Logger::_logger->error(buf, label, args...);
49+
static void error(const char* label, fmt::format_string<Args...> fmt, Args&&... args) {
50+
auto msg = fmt::format(fmt, std::forward<Args>(args)...);
51+
Logger::_logger->error("[{:12}] {}", label, msg);
6452
}
6553

6654
template <typename... Args>
67-
static void critical(const char* label, const char* fmt, const Args&... args) {
68-
char buf[LOGGER_BUFFER_SIZE];
69-
std::memset(buf, 0, LOGGER_BUFFER_SIZE);
70-
strcat(buf, "[{:12}] ");
71-
strcat(buf, fmt);
72-
Logger::_logger->critical(buf, label, args...);
55+
static void critical(const char* label, fmt::format_string<Args...> fmt, Args&&... args) {
56+
auto msg = fmt::format(fmt, std::forward<Args>(args)...);
57+
Logger::_logger->critical("[{:12}] {}", label, msg);
7358
}
7459

7560
static void flush() { Logger::_logger->flush(); }
@@ -84,15 +69,11 @@ class Logger {
8469
};
8570

8671
template <typename... Args>
87-
std::string colored(const char* color, const char* fmt, const Args&... args) {
72+
std::string colored(const char* color, fmt::format_string<Args...> fmt, Args&&... args) {
8873
if (Logger::isColorLogEnabled()) {
89-
char buf[20];
90-
std::memset(buf, 0, 20);
91-
strcat(buf, "{}");
92-
strcat(buf, fmt);
93-
strcat(buf, "{}");
94-
return fmt::format(buf, color, args..., NC);
74+
auto msg = fmt::format(fmt, std::forward<Args>(args)...);
75+
return fmt::format("{}{}{}", color, msg, NC);
9576
} else {
96-
return fmt::format(fmt, args...);
77+
return fmt::format(fmt, std::forward<Args>(args)...);
9778
}
9879
}

0 commit comments

Comments
 (0)