allow logging to be disabled per-mod

This commit is contained in:
camila314 2023-09-08 12:44:26 -05:00
parent 1b77582242
commit 6d599a5e19
5 changed files with 33 additions and 5 deletions

View file

@ -394,6 +394,9 @@ namespace geode {
*/
ModJson getRuntimeInfo() const;
bool isLoggingEnabled() const;
void setLoggingEnabled(bool enabled);
friend class ModImpl;
};
}

View file

@ -222,12 +222,14 @@ void Logger::setup() {
}
void Logger::push(Log&& log) {
if (log.getSender()->isLoggingEnabled()) {
std::string logStr = log.toString(true, nestLevel());
LoaderImpl::get()->logConsoleMessageWithSeverity(logStr, log.getSeverity());
logStream() << logStr << std::endl;
logs().emplace_back(std::forward<Log>(log));
}
}
void Logger::pop(Log* log) {

View file

@ -231,6 +231,14 @@ ModJson Mod::getRuntimeInfo() const {
return m_impl->getRuntimeInfo();
}
bool Mod::isLoggingEnabled() const {
return m_impl->isLoggingEnabled();
}
void Mod::setLoggingEnabled(bool enabled) {
m_impl->setLoggingEnabled(enabled);
}
bool Mod::hasSavedValue(std::string const& key) {
return this->getSaveContainer().contains(key);
}

View file

@ -622,6 +622,14 @@ ModJson Mod::Impl::getRuntimeInfo() const {
return json;
}
bool Mod::Impl::isLoggingEnabled() const {
return m_loggingEnabled;
}
void Mod::Impl::setLoggingEnabled(bool enabled) {
m_loggingEnabled = enabled;
}
static Result<ModMetadata> getModImplInfo() {
std::string err;
json::Value json;

View file

@ -56,11 +56,15 @@ namespace geode {
* Settings save data. Stored for efficient loading of custom settings
*/
json::Value m_savedSettingsData = json::Object();
/**
* Whether the mod resources are loaded or not
*/
bool m_resourcesLoaded = false;
/**
* Whether logging is enabled for this mod
*/
bool m_loggingEnabled = true;
ModRequestedAction m_requestedAction = ModRequestedAction::None;
@ -139,6 +143,9 @@ namespace geode {
char const* expandSpriteName(char const* name);
ModJson getRuntimeInfo() const;
bool isLoggingEnabled() const;
void setLoggingEnabled(bool enabled);
};
class ModImpl : public Mod::Impl {