-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinitquit.cpp
More file actions
78 lines (70 loc) · 2.22 KB
/
initquit.cpp
File metadata and controls
78 lines (70 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//
// Created by Bobini on 05/02/2026.
//
#include <SDK/foobar2000.h>
#include <spdlog/spdlog.h>
#include <spdlog/sinks/base_sink.h>
#include <spdlog/pattern_formatter.h>
#include "mcp.h"
#include "preferences.h"
class foobar_sink : public spdlog::sinks::base_sink<std::mutex>
{
protected:
void sink_it_(const spdlog::details::log_msg& msg) override
{
spdlog::memory_buf_t formatted;
formatter_->format(msg, formatted);
const auto str = fmt::to_string(formatted);
switch (spdlog::level::level_enum level = msg.level)
{
case spdlog::level::trace:
FB2K_console_formatter() << "[TRACE] " << str.c_str();
break;
case spdlog::level::debug:
FB2K_console_formatter() << "[DEBUG] " << str.c_str();
break;
case spdlog::level::info:
FB2K_console_formatter() << "[INFO] " << str.c_str();
break;
case spdlog::level::warn:
FB2K_console_formatter() << "[WARN] " << str.c_str();
break;
case spdlog::level::err:
FB2K_console_formatter() << "[ERROR] " << str.c_str();
break;
case spdlog::level::critical:
FB2K_console_formatter() << "[CRITICAL] " << str.c_str();
break;
default:
FB2K_console_formatter() << "[UNKNOWN] " << str.c_str();
break;
}
}
void flush_() override
{
}
};
class myinitquit : public initquit
{
public:
void on_init() override
{
#ifdef _DEBUG
spdlog::set_level(spdlog::level::debug);
#else
spdlog::set_level(spdlog::level::err);
#endif
const auto logger = std::make_shared<spdlog::logger>("foobar_ai", std::make_shared<foobar_sink>());
// Set formatter without newline at the end
auto f = std::make_unique<spdlog::pattern_formatter>("[%n] [%Y-%m-%d %H:%M:%S.%e] [%l] %v", spdlog::pattern_time_type::local, "");
logger->set_formatter(std::move(f));
spdlog::set_default_logger(logger);
// Start server if enabled
foo_ai::restart_mcp_server();
}
void on_quit() override
{
mcp_manager::instance().stop();
}
};
static initquit_factory_t<myinitquit> g_myinitquit_factory;