-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogging.hpp
More file actions
55 lines (47 loc) · 1.21 KB
/
logging.hpp
File metadata and controls
55 lines (47 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/**
* @file logging.hpp
* @brief Logging helpers for gnuplotpp examples and runtime diagnostics.
*/
#pragma once
#include <iostream>
#include <sstream>
#include <string>
#include <utility>
#ifdef GNUPLOTPP_HAS_SPDLOG
#include <spdlog/spdlog.h>
#endif
namespace gnuplotpp::log {
template <typename... Args>
inline std::string BuildMessage(Args&&... args) {
std::ostringstream oss;
(oss << ... << std::forward<Args>(args));
return oss.str();
}
template <typename... Args>
inline void Info(Args&&... args) {
const auto msg = BuildMessage(std::forward<Args>(args)...);
#ifdef GNUPLOTPP_HAS_SPDLOG
spdlog::info("{}", msg);
#else
std::clog << "[gnuplotpp] info: " << msg << "\n";
#endif
}
template <typename... Args>
inline void Warn(Args&&... args) {
const auto msg = BuildMessage(std::forward<Args>(args)...);
#ifdef GNUPLOTPP_HAS_SPDLOG
spdlog::warn("{}", msg);
#else
std::clog << "[gnuplotpp] warn: " << msg << "\n";
#endif
}
template <typename... Args>
inline void Error(Args&&... args) {
const auto msg = BuildMessage(std::forward<Args>(args)...);
#ifdef GNUPLOTPP_HAS_SPDLOG
spdlog::error("{}", msg);
#else
std::clog << "[gnuplotpp] error: " << msg << "\n";
#endif
}
} // namespace gnuplotpp::log