libdl  0.0.1
Simple yet powerful deep learning
Loading...
Searching...
No Matches
logging.hpp
1#pragma once
2
3#include <memory>
4
5#include <spdlog/spdlog.h>
6
7namespace dl::logging {
8 using LoggerPtr = std::shared_ptr<spdlog::logger>;
9
10 enum class Verbosity : int { Off, Critical, Error, Warning, Info, Debug, Trace };
11
12 const char* getVersionStr() noexcept;
13
19 void setVerbosity(Verbosity verbosity) noexcept;
20
28 LoggerPtr getLogger(std::string name);
29} // namespace dl::logging
30
32// Custom loggable types //
34#include <spdlog/fmt/bundled/format.h>
35
36template <typename T>
37struct fmt::formatter<std::optional<T>> {
38 constexpr auto parse(format_parse_context& ctx) -> decltype(ctx.begin()) { return ctx.end(); }
39
40 template <typename FormatContext>
41 auto format(const std::optional<T>& input, FormatContext& ctx) -> decltype(ctx.out()) {
42 if (input.has_value())
43 return fmt::format_to(ctx.out(), "{}", input.value());
44 return fmt::format_to(ctx.out(), "<EMPTY>");
45 }
46};
47
49template <typename T>
50struct fmt::formatter<std::vector<T>> {
51 constexpr auto parse(format_parse_context& ctx) -> decltype(ctx.begin()) { return ctx.end(); }
52
53 template <typename FormatContext>
54 auto format(const std::vector<T>& input, FormatContext& ctx) -> decltype(ctx.out()) {
55 return fmt::format_to(ctx.out(), "{{{}}}", fmt::join(input, ", "));
56 }
57};