Brenta Engine 1.2
Loading...
Searching...
No Matches
logger.hpp
1// SPDX-License-Identifier: MIT
2// Author: Giovanni Santini
3// Mail: giovanni.santini@proton.me
4// Github: @San7o
5
6#pragma once
7
8#include <brenta/subsystem.hpp>
9#include <oak/oak.hpp>
10
11#include <tenno/vector.hpp>
12
13#include <fstream>
14#include <expected>
15#include <string>
16#include <filesystem>
17
18#define DEBUG(...) OAK_DEBUG(__VA_ARGS__);
19#define INFO(...) OAK_INFO(__VA_ARGS__);
20#define WARN(...) OAK_WARN(__VA_ARGS__);
21#define ERROR(...) OAK_ERROR(__VA_ARGS__);
22#define EVENT(type, ...) OAK_EVENT(type, __VA_ARGS__)
23
24namespace brenta
25{
26
27//
28// Logging
29// -------
30//
31// The engine uses `oak` for logging. You can use its powerful API
32// to log whatever you want. The logging subsystem initialized some
33// settings and it is ment as the engine's "standard" way to
34// configure its global logger when the application starts.
35//
36class Logger : public Subsystem
37{
38public:
39
40 enum Event
41 {
42 Lifetime,
43 Callback,
44 Signal,
45 };
46
47 using Level = oak::Level;
48 using Flags = oak::Flags;
49
50 struct Config;
51 class Builder;
52
53 // Subsystem interface
54 static const std::string subsystem_name;
55 bool is_initialized() override;
56 std::string name() override;
57 std::expected<void, Subsystem::Error> initialize() override;
58 std::expected<void, Subsystem::Error> terminate() override;
59
60
61 // Member functions
62
63 static Logger& instance();
64 static std::string event_name(enum Event event);
65
66private:
67
68 static Config init_config;
69 static bool initialized;
70
71 // Private constructors / destructors for singleton
72 Logger() = default;
73 ~Logger() = default;
74
75};
76
78{
79 oak::Level log_level = oak::Level::Info;
80 std::filesystem::path log_file = "/tmp/brenta-logs.txt";
81 tenno::vector<Event> events = {};
82 tenno::vector<Flags> flags = {};
83};
84
86{
87public:
88
89 Builder() = default;
90 ~Builder() = default;
91
92 Builder &level(Logger::Level log_level);
93 Builder &file(std::filesystem::path out_file);
94 Builder &event(Logger::Event event);
95 Builder &flag(Logger::Flags flag);
96
97 Subsystem &build();
98
99private:
100
101 Logger::Config conf = {};
102
103
104};
105
106} // namespace brenta