Practical Tools for Simple Design
Loading...
Searching...
No Matches
Logger.hpp
1#ifndef UTIL_LOGGER_HPP
2#define UTIL_LOGGER_HPP
3
4#include "pch.hpp" // IWYU pragma: export
5
6#include <spdlog/spdlog.h>
7
8#include "Util/Transform.hpp"
9
10namespace Util::Logger {
17enum class Level {
18 TRACE,
19 DEBUG,
20 INFO,
21 WARN,
22 ERROR,
23 CRITICAL,
24};
25
31void Init();
32
43void SetLevel(Level level);
44
52Level GetLevel();
53
54#define LOG_TRACE(...) spdlog::trace(__VA_ARGS__)
55#define LOG_DEBUG(...) spdlog::debug(__VA_ARGS__)
56#define LOG_INFO(...) spdlog::info(__VA_ARGS__)
57#define LOG_WARN(...) spdlog::warn(__VA_ARGS__)
58#define LOG_ERROR(...) spdlog::error(__VA_ARGS__)
59#define LOG_CRITICAL(...) spdlog::critical(__VA_ARGS__)
60} // namespace Util::Logger
61
62/*
63 * I have no idea what this does
64 *
65 * Credit to: https://github.com/fmtlib/fmt/issues/3306#issuecomment-1432711988
66 */
67// NOLINTBEGIN
68template <glm::length_t L, typename Pre>
69struct fmt::formatter<glm::vec<L, Pre>> : fmt::formatter<Pre> {
70 auto format(const glm::vec<L, Pre> &vec, format_context &ctx) const
71 -> decltype(ctx.out()) {
72 return format_to(ctx.out(), "{}", glm::to_string(vec));
73 }
74};
75
76template <glm::length_t C, glm::length_t R, typename Pre>
77struct fmt::formatter<glm::mat<C, R, Pre>> : fmt::formatter<Pre> {
78 auto format(const glm::mat<C, R, Pre> &mat, format_context &ctx) const
79 -> decltype(ctx.out()) {
80 return format_to(ctx.out(), "{}", glm::to_string(mat));
81 }
82};
83
84template <>
85struct fmt::formatter<Util::Transform> : fmt::formatter<std::string> {
86 auto format(const Util::Transform &t, format_context &ctx) const
87 -> decltype(ctx.out()) {
88 return format_to(ctx.out(), "T: {} R: {} rad S: {}", t.translation,
89 t.rotation, t.scale);
90 }
91};
92// NOLINTEND
93
94#endif
Useful tools for development.
Definition: Animation.hpp:12
A struct representing a transformation in 2D space.
Definition: Transform.hpp:16
float rotation
The rotation of the transformation.
Definition: Transform.hpp:32
glm::vec2 scale
The scale of the transformation.
Definition: Transform.hpp:40
glm::vec2 translation
The translation of the transformation.
Definition: Transform.hpp:23