summaryrefslogtreecommitdiff
path: root/log.cpp
diff options
context:
space:
mode:
authorRusty Wagner <rusty.wagner@gmail.com>2025-11-04 19:23:44 -0500
committerRusty Wagner <rusty.wagner@gmail.com>2025-11-04 20:48:56 -0500
commit21324fa57b44ba77e46be4952a02484cb8c3ef5c (patch)
tree7cb747c5c1a670ac799596e5bc645931f1f69a39 /log.cpp
parent864374e250e87901bbbad66086abb9c0b5924022 (diff)
Remove indenting APIs from Logger. These are thread unsafe by design.
Loggers are not owned by a specific thread and many are used by multiple threads. The indenting APIs could not be made to be thread safe in any way as they exist, so they have been removed. The data races caused by the indenting APIs are actually an important stability issue that could cause the indentation level to go out of bounds and crash the product. If you were using the indentation APIs, you will need to rewrite the usage to manually manage the indentation level in a thread safe way.
Diffstat (limited to 'log.cpp')
-rw-r--r--log.cpp73
1 files changed, 21 insertions, 52 deletions
diff --git a/log.cpp b/log.cpp
index e6abe48b..9edb4e4f 100644
--- a/log.cpp
+++ b/log.cpp
@@ -486,7 +486,7 @@ void Logger::Log(BNLogLevel level, const char* fmt, ...)
{
va_list args;
va_start(args, fmt);
- PerformLog(GetSessionId(), level, GetName(), GetThreadId(), fmt::format("{}{}", GetIndent(), fmt).c_str(), args);
+ PerformLog(GetSessionId(), level, GetName(), GetThreadId(), fmt, args);
va_end(args);
}
@@ -496,7 +496,7 @@ void Logger::LogTrace(const char* fmt, ...)
#ifdef BN_ENABLE_LOG_TRACE
va_list args;
va_start(args, fmt);
- PerformLog(GetSessionId(), DebugLog, GetName(), GetThreadId(), fmt::format("{}{}", GetIndent(), fmt).c_str(), args);
+ PerformLog(GetSessionId(), DebugLog, GetName(), GetThreadId(), fmt, args);
va_end(args);
#endif
}
@@ -506,7 +506,7 @@ void Logger::LogDebug(const char* fmt, ...)
{
va_list args;
va_start(args, fmt);
- PerformLog(GetSessionId(), DebugLog, GetName(), GetThreadId(), fmt::format("{}{}", GetIndent(), fmt).c_str(), args);
+ PerformLog(GetSessionId(), DebugLog, GetName(), GetThreadId(), fmt, args);
va_end(args);
}
@@ -515,7 +515,7 @@ void Logger::LogInfo(const char* fmt, ...)
{
va_list args;
va_start(args, fmt);
- PerformLog(GetSessionId(), InfoLog, GetName(), GetThreadId(), fmt::format("{}{}", GetIndent(), fmt).c_str(), args);
+ PerformLog(GetSessionId(), InfoLog, GetName(), GetThreadId(), fmt, args);
va_end(args);
}
@@ -524,7 +524,7 @@ void Logger::LogWarn(const char* fmt, ...)
{
va_list args;
va_start(args, fmt);
- PerformLog(GetSessionId(), WarningLog, GetName(), GetThreadId(), fmt::format("{}{}", GetIndent(), fmt).c_str(), args);
+ PerformLog(GetSessionId(), WarningLog, GetName(), GetThreadId(), fmt, args);
va_end(args);
}
@@ -533,7 +533,7 @@ void Logger::LogError(const char* fmt, ...)
{
va_list args;
va_start(args, fmt);
- PerformLog(GetSessionId(), ErrorLog, GetName(), GetThreadId(), fmt::format("{}{}", GetIndent(), fmt).c_str(), args);
+ PerformLog(GetSessionId(), ErrorLog, GetName(), GetThreadId(), fmt, args);
va_end(args);
}
@@ -542,7 +542,7 @@ void Logger::LogAlert(const char* fmt, ...)
{
va_list args;
va_start(args, fmt);
- PerformLog(GetSessionId(), AlertLog, GetName(), GetThreadId(), fmt::format("{}{}", GetIndent(), fmt).c_str(), args);
+ PerformLog(GetSessionId(), AlertLog, GetName(), GetThreadId(), fmt, args);
va_end(args);
}
@@ -552,7 +552,7 @@ void Logger::LogForException(BNLogLevel level, const std::exception& e, const ch
va_list args;
va_start(args, fmt);
PerformLogForException(
- GetSessionId(), level, GetName(), GetThreadId(), e, fmt::format("{}{}", GetIndent(), fmt).c_str(), args);
+ GetSessionId(), level, GetName(), GetThreadId(), e, fmt, args);
va_end(args);
}
@@ -563,7 +563,7 @@ void Logger::LogTraceForException(const std::exception& e, const char* fmt, ...)
va_list args;
va_start(args, fmt);
PerformLogForException(
- GetSessionId(), DebugLog, GetName(), GetThreadId(), e, fmt::format("{}{}", GetIndent(), fmt).c_str(), args);
+ GetSessionId(), DebugLog, GetName(), GetThreadId(), e, fmt, args);
va_end(args);
#endif
}
@@ -574,7 +574,7 @@ void Logger::LogDebugForException(const std::exception& e, const char* fmt, ...)
va_list args;
va_start(args, fmt);
PerformLogForException(
- GetSessionId(), DebugLog, GetName(), GetThreadId(), e, fmt::format("{}{}", GetIndent(), fmt).c_str(), args);
+ GetSessionId(), DebugLog, GetName(), GetThreadId(), e, fmt, args);
va_end(args);
}
@@ -584,7 +584,7 @@ void Logger::LogInfoForException(const std::exception& e, const char* fmt, ...)
va_list args;
va_start(args, fmt);
PerformLogForException(
- GetSessionId(), InfoLog, GetName(), GetThreadId(), e, fmt::format("{}{}", GetIndent(), fmt).c_str(), args);
+ GetSessionId(), InfoLog, GetName(), GetThreadId(), e, fmt, args);
va_end(args);
}
@@ -594,7 +594,7 @@ void Logger::LogWarnForException(const std::exception& e, const char* fmt, ...)
va_list args;
va_start(args, fmt);
PerformLogForException(
- GetSessionId(), WarningLog, GetName(), GetThreadId(), e, fmt::format("{}{}", GetIndent(), fmt).c_str(), args);
+ GetSessionId(), WarningLog, GetName(), GetThreadId(), e, fmt, args);
va_end(args);
}
@@ -604,7 +604,7 @@ void Logger::LogErrorForException(const std::exception& e, const char* fmt, ...)
va_list args;
va_start(args, fmt);
PerformLogForException(
- GetSessionId(), ErrorLog, GetName(), GetThreadId(), e, fmt::format("{}{}", GetIndent(), fmt).c_str(), args);
+ GetSessionId(), ErrorLog, GetName(), GetThreadId(), e, fmt, args);
va_end(args);
}
@@ -614,7 +614,7 @@ void Logger::LogAlertForException(const std::exception& e, const char* fmt, ...)
va_list args;
va_start(args, fmt);
PerformLogForException(
- GetSessionId(), AlertLog, GetName(), GetThreadId(), e, fmt::format("{}{}", GetIndent(), fmt).c_str(), args);
+ GetSessionId(), AlertLog, GetName(), GetThreadId(), e, fmt, args);
va_end(args);
}
@@ -624,7 +624,7 @@ void Logger::LogWithStackTrace(BNLogLevel level, const char* fmt, ...)
va_list args;
va_start(args, fmt);
PerformLogWithStackTrace(
- GetSessionId(), level, GetName(), GetThreadId(), fmt::format("{}{}", GetIndent(), fmt).c_str(), args);
+ GetSessionId(), level, GetName(), GetThreadId(), fmt, args);
va_end(args);
}
@@ -635,7 +635,7 @@ void Logger::LogTraceWithStackTrace(const char* fmt, ...)
va_list args;
va_start(args, fmt);
PerformLogWithStackTrace(
- GetSessionId(), DebugLog, GetName(), GetThreadId(), fmt::format("{}{}", GetIndent(), fmt).c_str(), args);
+ GetSessionId(), DebugLog, GetName(), GetThreadId(), fmt, args);
va_end(args);
#endif
}
@@ -646,7 +646,7 @@ void Logger::LogDebugWithStackTrace(const char* fmt, ...)
va_list args;
va_start(args, fmt);
PerformLogWithStackTrace(
- GetSessionId(), DebugLog, GetName(), GetThreadId(), fmt::format("{}{}", GetIndent(), fmt).c_str(), args);
+ GetSessionId(), DebugLog, GetName(), GetThreadId(), fmt, args);
va_end(args);
}
@@ -656,7 +656,7 @@ void Logger::LogInfoWithStackTrace(const char* fmt, ...)
va_list args;
va_start(args, fmt);
PerformLogWithStackTrace(
- GetSessionId(), InfoLog, GetName(), GetThreadId(), fmt::format("{}{}", GetIndent(), fmt).c_str(), args);
+ GetSessionId(), InfoLog, GetName(), GetThreadId(), fmt, args);
va_end(args);
}
@@ -666,7 +666,7 @@ void Logger::LogWarnWithStackTrace(const char* fmt, ...)
va_list args;
va_start(args, fmt);
PerformLogWithStackTrace(
- GetSessionId(), WarningLog, GetName(), GetThreadId(), fmt::format("{}{}", GetIndent(), fmt).c_str(), args);
+ GetSessionId(), WarningLog, GetName(), GetThreadId(), fmt, args);
va_end(args);
}
@@ -676,7 +676,7 @@ void Logger::LogErrorWithStackTrace(const char* fmt, ...)
va_list args;
va_start(args, fmt);
PerformLogWithStackTrace(
- GetSessionId(), ErrorLog, GetName(), GetThreadId(), fmt::format("{}{}", GetIndent(), fmt).c_str(), args);
+ GetSessionId(), ErrorLog, GetName(), GetThreadId(), fmt, args);
va_end(args);
}
@@ -686,7 +686,7 @@ void Logger::LogAlertWithStackTrace(const char* fmt, ...)
va_list args;
va_start(args, fmt);
PerformLogWithStackTrace(
- GetSessionId(), AlertLog, GetName(), GetThreadId(), fmt::format("{}{}", GetIndent(), fmt).c_str(), args);
+ GetSessionId(), AlertLog, GetName(), GetThreadId(), fmt, args);
va_end(args);
}
@@ -749,37 +749,6 @@ size_t Logger::GetSessionId()
}
-void Logger::Indent()
-{
- BNLoggerIndent(m_object);
-}
-
-
-void Logger::Dedent()
-{
- BNLoggerDedent(m_object);
-}
-
-
-void Logger::ResetIndent()
-{
- BNLoggerResetIndent(m_object);
-}
-
-
-string Logger::GetIndent() const
-{
- char* indent = BNGetLoggerIndent(m_object);
- if (!indent)
- {
- return "";
- }
- string result = indent;
- BNFreeString(indent);
- return result;
-}
-
-
Ref<Logger> LogRegistry::CreateLogger(const std::string& loggerName, size_t sessionId)
{
return new Logger(BNLogCreateLogger(loggerName.c_str(), sessionId));