C++ Essence Library 0.1.0
A Utility Library for Modern C++ Programming
Loading...
Searching...
No Matches
spdlog_extension.hpp
1/*
2 * Copyright (c) 2024 The RefValue Project
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 * THE SOFTWARE.
21 */
22
23#pragma once
24
25#include "globalization/globalized_arg.hpp"
26
27#include <utility>
28
29#include <spdlog/spdlog.h>
30
31namespace spdlog::detail {
32 inline constexpr auto spdlog_info_func = []<typename... Args>(
33 Args&&... args) { spdlog::info(std::forward<Args>(args)...); };
34
35 inline constexpr auto spdlog_trace_func = []<typename... Args>(
36 Args&&... args) { spdlog::trace(std::forward<Args>(args)...); };
37
38 inline constexpr auto spdlog_warn_func = []<typename... Args>(
39 Args&&... args) { spdlog::warn(std::forward<Args>(args)...); };
40
41 inline constexpr auto spdlog_error_func = []<typename... Args>(
42 Args&&... args) { spdlog::error(std::forward<Args>(args)...); };
43
44 template <auto LogArgsFunc, typename... Args>
45 void glog_args(const std::locale& locale, format_string_t<essence::globalization::globalized_arg_t<Args>...> fmt,
46 Args&&... args) {
47 LogArgsFunc(fmt, essence::globalization::make_globalized_arg(locale, std::forward<Args>(args))...);
48 }
49
50 template <auto LogOneFunc, typename T>
51 void glog_one(const std::locale& locale, const T& msg) {
52 LogOneFunc(essence::globalization::make_globalized_arg(locale, msg));
53 }
54} // namespace spdlog::detail
55
56namespace spdlog {
57 template <typename... Args>
58 void ginfo(const std::locale& locale, format_string_t<essence::globalization::globalized_arg_t<Args>...> fmt,
59 Args&&... args) {
60 detail::glog_args<detail::spdlog_info_func>(locale, fmt, std::forward<Args>(args)...);
61 }
62
63 template <typename T>
64 void ginfo(const std::locale& locale, const T& msg) {
65 detail::glog_one<detail::spdlog_info_func>(locale, msg);
66 }
67
68 template <typename... Args>
69 void gtrace(const std::locale& locale, format_string_t<essence::globalization::globalized_arg_t<Args>...> fmt,
70 Args&&... args) {
71 detail::glog_args<detail::spdlog_trace_func>(locale, fmt, std::forward<Args>(args)...);
72 }
73
74 template <typename T>
75 void gtrace(const std::locale& locale, const T& msg) {
76 detail::glog_one<detail::spdlog_trace_func>(locale, msg);
77 }
78
79 template <typename... Args>
80 void gwarn(const std::locale& locale, format_string_t<essence::globalization::globalized_arg_t<Args>...> fmt,
81 Args&&... args) {
82 detail::glog_args<detail::spdlog_warn_func>(locale, fmt, std::forward<Args>(args)...);
83 }
84
85 template <typename T>
86 void gwarn(const std::locale& locale, const T& msg) {
87 detail::glog_one<detail::spdlog_warn_func>(locale, msg);
88 }
89
90 template <typename... Args>
91 void gerror(const std::locale& locale, format_string_t<essence::globalization::globalized_arg_t<Args>...> fmt,
92 Args&&... args) {
93 detail::glog_args<detail::spdlog_error_func>(locale, fmt, std::forward<Args>(args)...);
94 }
95
96 template <typename T>
97 void gerror(const std::locale& locale, const T& msg) {
98 detail::glog_one<detail::spdlog_error_func>(locale, msg);
99 }
100} // namespace spdlog