3#include <spdlog/sinks/callback_sink.h>
4#include <spdlog/sinks/dist_sink.h>
5#include <spdlog/spdlog.h>
6#include <spdlog/fmt/chrono.h>
7#include <spdlog/fmt/ranges.h>
9#include <hpp/source_location.hpp>
16#define APPLOG_DEBUG(...) SPDLOG_LOGGER_CALL(spdlog::get(APPLOG), spdlog::level::debug, __VA_ARGS__)
17#define APPLOG_TRACE(...) SPDLOG_LOGGER_CALL(spdlog::get(APPLOG), spdlog::level::trace, __VA_ARGS__)
18#define APPLOG_INFO(...) SPDLOG_LOGGER_CALL(spdlog::get(APPLOG), spdlog::level::info, __VA_ARGS__)
19#define APPLOG_WARNING(...) SPDLOG_LOGGER_CALL(spdlog::get(APPLOG), spdlog::level::warn, __VA_ARGS__)
20#define APPLOG_ERROR(...) SPDLOG_LOGGER_CALL(spdlog::get(APPLOG), spdlog::level::err, __VA_ARGS__)
21#define APPLOG_CRITICAL(...) SPDLOG_LOGGER_CALL(spdlog::get(APPLOG), spdlog::level::critical, __VA_ARGS__)
24#ifndef SPDLOG_NO_SOURCE_LOC
25#define SPDLOG_LOGGER_CALL_LOC(logger, file, line, func, level, ...) \
26 (logger)->log(spdlog::source_loc{file, line, func}, level, __VA_ARGS__)
28#define SPDLOG_LOGGER_CALL_LOC(logger, level, ...) (logger)->log(spdlog::source_loc{}, level, __VA_ARGS__)
30#define APPLOG_DEBUG_LOC(FILE_LOC, LINE_LOC, FUNC_LOC, ...) \
31SPDLOG_LOGGER_CALL_LOC(spdlog::get(APPLOG), FILE_LOC, LINE_LOC, FUNC_LOC, spdlog::level::debug, __VA_ARGS__)
32#define APPLOG_TRACE_LOC(FILE_LOC, LINE_LOC, FUNC_LOC, ...) \
33 SPDLOG_LOGGER_CALL_LOC(spdlog::get(APPLOG), FILE_LOC, LINE_LOC, FUNC_LOC, spdlog::level::trace, __VA_ARGS__)
34#define APPLOG_INFO_LOC(FILE_LOC, LINE_LOC, FUNC_LOC, ...) \
35 SPDLOG_LOGGER_CALL_LOC(spdlog::get(APPLOG), FILE_LOC, LINE_LOC, FUNC_LOC, spdlog::level::info, __VA_ARGS__)
36#define APPLOG_WARNING_LOC(FILE_LOC, LINE_LOC, FUNC_LOC, ...) \
37 SPDLOG_LOGGER_CALL_LOC(spdlog::get(APPLOG), FILE_LOC, LINE_LOC, FUNC_LOC, spdlog::level::warn, __VA_ARGS__)
38#define APPLOG_ERROR_LOC(FILE_LOC, LINE_LOC, FUNC_LOC, ...) \
39 SPDLOG_LOGGER_CALL_LOC(spdlog::get(APPLOG), FILE_LOC, LINE_LOC, FUNC_LOC, spdlog::level::err, __VA_ARGS__)
40#define APPLOG_CRITICAL_LOC(FILE_LOC, LINE_LOC, FUNC_LOC, ...) \
41 SPDLOG_LOGGER_CALL_LOC(spdlog::get(APPLOG), FILE_LOC, LINE_LOC, FUNC_LOC, spdlog::level::critical, __VA_ARGS__)
43#define APPLOG_FLUSH() spdlog::apply_all([](std::shared_ptr<spdlog::logger> const& lg){ lg->flush(); })
50 logging(
const std::string& output_file =
"Log.txt");
55template<spdlog::level::level_enum lvl = spdlog::level::debug,
typename T = std::chrono::microseconds>
58 using clock_t = std::chrono::high_resolution_clock;
65 log_stopwatch(
const char* func, hpp::source_location loc = hpp::source_location::current())
74 auto end = clock_t::now();
75 auto dur = std::chrono::duration_cast<T>(end -
start);
83#define APPLOG_CONCATENATE_DETAIL(x, y) x##y
84#define APPLOG_CONCATENATE(x, y) APPLOG_CONCATENATE_DETAIL(x, y)
87#define APPLOG_UNIQUE_VAR(prefix) APPLOG_CONCATENATE(prefix, __LINE__)
89#define APPLOG_INFO_PERF(T) log_stopwatch<spdlog::level::info, T> APPLOG_UNIQUE_VAR(_test)(__func__);
90#define APPLOG_TRACE_PERF(T) log_stopwatch<spdlog::level::trace, T> APPLOG_UNIQUE_VAR(_test)(__func__);
91#define APPLOG_DEBUG_PERF(T) log_stopwatch<spdlog::level::debug, T> APPLOG_UNIQUE_VAR(_test)(__func__);
94#define APPLOG_INFO_PERF_NAMED(T, name) log_stopwatch<spdlog::level::info, T> APPLOG_UNIQUE_VAR(_test)(name);
95#define APPLOG_TRACE_PERF_NAMED(T, name) log_stopwatch<spdlog::level::trace, T> APPLOG_UNIQUE_VAR(_test)(name);
96#define APPLOG_DEBUG_PERF_NAMED(T, name) log_stopwatch<spdlog::level::trace, T> APPLOG_UNIQUE_VAR(_test)(name);
#define SPDLOG_LOGGER_CALL_LOC(logger, file, line, func, level,...)
auto get_mutable_logging_container() -> std::shared_ptr< spdlog::sinks::dist_sink_mt >
log_stopwatch(const char *func, hpp::source_location loc=hpp::source_location::current())
hpp::source_location location_
std::chrono::high_resolution_clock clock_t
clock_t::time_point timepoint_t
logging(const std::string &output_file="Log.txt")