Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plugins: Allow plugins to customize their log colors #823

Merged
merged 10 commits into from
Oct 14, 2024
5 changes: 5 additions & 0 deletions primedev/plugins/interfaces/IPluginId.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ enum class PluginString : int
enum class PluginField : int
{
CONTEXT = 0,
COLOR = 1,
};

// an interface that is required from every plugin to query data about it
Expand All @@ -26,6 +27,10 @@ class IPluginId
public:
virtual const char* GetString(PluginString prop) = 0;
virtual int64_t GetField(PluginField prop) = 0;

static const int64_t COLOR_R_MASK = 0xFF;
uniboi marked this conversation as resolved.
Show resolved Hide resolved
static const int64_t COLOR_G_MASK = COLOR_R_MASK << 8;
static const int64_t COLOR_B_MASK = COLOR_G_MASK << 8;
};

#endif
11 changes: 10 additions & 1 deletion primedev/plugins/plugins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ Plugin::Plugin(std::string path)
m_runOnServer = context & PluginContext::DEDICATED;
m_runOnClient = context & PluginContext::CLIENT;

int64_t logColor = m_pluginId->GetField(PluginField::COLOR);
if ((logColor & 0xFFFFFF) != 0)
uniboi marked this conversation as resolved.
Show resolved Hide resolved
{
m_logColor = Color(
(int)(logColor & IPluginId::COLOR_R_MASK),
(int)((logColor & IPluginId::COLOR_G_MASK) >> 8),
(int)((logColor & IPluginId::COLOR_B_MASK) >> 16));
}

if (!name)
{
NS::log::PLUGINSYS->error("Could not load name of plugin at '{}'", path);
Expand Down Expand Up @@ -106,7 +115,7 @@ Plugin::Plugin(std::string path)
return;
}

m_logger = std::make_shared<ColoredLogger>(m_logName, NS::Colors::PLUGIN);
m_logger = std::make_shared<ColoredLogger>(m_logName, m_logColor);
RegisterLogger(m_logger);

if (IsDedicatedServer() && !m_runOnServer)
Expand Down
1 change: 1 addition & 0 deletions primedev/plugins/plugins.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class Plugin
std::string m_location; // path of the dll
bool m_runOnServer;
bool m_runOnClient;
Color m_logColor = NS::Colors::PLUGIN;
uniboi marked this conversation as resolved.
Show resolved Hide resolved

public:
HMODULE m_handle;
Expand Down