aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorGravatar Sadie Powell2025-01-11 16:45:15 +0000
committerGravatar Sadie Powell2025-01-11 16:51:34 +0000
commitc6238d80dee66bcefa92220a35d582ab739aa8a5 (patch)
tree180f082eda2b11986a0c9492ce6a63b3aceed11e /include
parentSynchronise the snomask list with th list from the docs site. (diff)
Don't format log messages if we can't actually log them.
This should prevent debug messages from potentially causing performance issues on production servers.
Diffstat (limited to 'include')
-rw-r--r--include/logging.h32
1 files changed, 25 insertions, 7 deletions
diff --git a/include/logging.h b/include/logging.h
index 79365f097..e613761a7 100644
--- a/include/logging.h
+++ b/include/logging.h
@@ -51,6 +51,12 @@ namespace Log
/** A sensitive message that we should not store lightly. */
RAWIO = 4,
+
+ /** The lowest log level supported. */
+ LOWEST = CRITICAL,
+
+ /** The highest log level supported. */
+ HIGHEST = RAWIO,
};
/** Converts a log level to a string.
@@ -236,8 +242,11 @@ private:
/** Whether we are currently logging to a file. */
bool logging = false;
- /** Check whether raw logging is enabled. */
- void CheckRawLog();
+ /** The highest level that loggers will accept. */
+ Log::Level maxlevel = Level::HIGHEST;
+
+ /** Check for the highest log level and warn about raw logging */
+ void CheckLevel();
/** Writes a message to the server log.
* @param level The level to log at.
@@ -246,6 +255,15 @@ private:
*/
void Write(Level level, const std::string& type, const std::string& message);
+ template <typename... Args>
+ void Write(Level level, const std::string& type, const char* format, Args&&... args)
+ {
+ if (maxlevel < level && !caching)
+ return; // No loggers care about this message.
+
+ Write(level, type, fmt::vformat(format, fmt::make_format_args(args...)));
+ }
+
public:
Manager();
@@ -283,7 +301,7 @@ public:
template <typename... Args>
void Critical(const std::string& type, const char* format, Args&&... args)
{
- Write(Level::CRITICAL, type, fmt::vformat(format, fmt::make_format_args(args...)));
+ Write(Level::CRITICAL, type, format, std::forward<Args>(args)...);
}
/** Writes a warning message to the server log.
@@ -303,7 +321,7 @@ public:
template <typename... Args>
void Warning(const std::string& type, const char* format, Args&&... args)
{
- Write(Level::WARNING, type, fmt::vformat(format, fmt::make_format_args(args...)));
+ Write(Level::WARNING, type, format, std::forward<Args>(args)...);
}
/** Writes a normal message to the server log.
@@ -323,7 +341,7 @@ public:
template <typename... Args>
void Normal(const std::string& type, const char* format, Args&&... args)
{
- Write(Level::NORMAL, type, fmt::vformat(format, fmt::make_format_args(args...)));
+ Write(Level::NORMAL, type, format, std::forward<Args>(args)...);
}
/** Writes a debug message to the server log.
@@ -342,7 +360,7 @@ public:
template <typename... Args>
void Debug(const std::string& type, const char* format, Args&&... args)
{
- Write(Level::DEBUG, type, fmt::vformat(format, fmt::make_format_args(args...)));
+ Write(Level::DEBUG, type, format, std::forward<Args>(args)...);
}
/** Writes a raw I/O message to the server log.
@@ -362,6 +380,6 @@ public:
template <typename... Args>
void RawIO(const std::string& type, const char* format, Args&&... args)
{
- Write(Level::RAWIO, type, fmt::vformat(format, fmt::make_format_args(args...)));
+ Write(Level::RAWIO, type, format, std::forward<Args>(args)...);
}
};