Remove static_cast (#2815)
* Remove static_cast * Add additional checks around our Logger::Level to ensure its lock_free
This commit is contained in:
parent
8070ab2392
commit
bb8b889cf5
@ -11,16 +11,16 @@
|
||||
|
||||
namespace Azure { namespace Core { namespace Diagnostics { namespace _internal {
|
||||
class Log final {
|
||||
using LogLevelInt = std::underlying_type<Logger::Level>::type;
|
||||
|
||||
static_assert(
|
||||
std::is_same<int, LogLevelInt>::value == true && ATOMIC_INT_LOCK_FREE == 2,
|
||||
std::is_same<int, std::underlying_type<Logger::Level>::type>::value == true,
|
||||
"Logger::Level values must be representable as lock-free");
|
||||
|
||||
static_assert(ATOMIC_INT_LOCK_FREE == 2, "atomic<int> must be lock-free");
|
||||
|
||||
static_assert(ATOMIC_BOOL_LOCK_FREE == 2, "atomic<bool> must be lock-free");
|
||||
|
||||
static AZ_CORE_DLLEXPORT std::atomic<bool> g_isLoggingEnabled;
|
||||
static AZ_CORE_DLLEXPORT std::atomic<LogLevelInt> g_logLevel;
|
||||
static AZ_CORE_DLLEXPORT std::atomic<Logger::Level> g_logLevel;
|
||||
|
||||
Log() = delete;
|
||||
~Log() = delete;
|
||||
@ -28,7 +28,7 @@ namespace Azure { namespace Core { namespace Diagnostics { namespace _internal {
|
||||
public:
|
||||
static bool ShouldWrite(Logger::Level level)
|
||||
{
|
||||
return g_isLoggingEnabled && static_cast<LogLevelInt>(level) >= g_logLevel;
|
||||
return g_isLoggingEnabled && level >= g_logLevel;
|
||||
}
|
||||
|
||||
static void Write(Logger::Level level, std::string const& message);
|
||||
|
||||
@ -21,15 +21,12 @@ static std::function<void(Logger::Level level, std::string const& message)> g_lo
|
||||
std::atomic<bool> Log::g_isLoggingEnabled(
|
||||
_detail::EnvironmentLogLevelListener::GetLogListener() != nullptr);
|
||||
|
||||
std::atomic<Log::LogLevelInt> Log::g_logLevel(static_cast<LogLevelInt>(
|
||||
_detail::EnvironmentLogLevelListener::GetLogLevel(Logger::Level::Warning)));
|
||||
std::atomic<Logger::Level> Log::g_logLevel(
|
||||
_detail::EnvironmentLogLevelListener::GetLogLevel(Logger::Level::Warning));
|
||||
|
||||
inline void Log::EnableLogging(bool isEnabled) { g_isLoggingEnabled = isEnabled; }
|
||||
|
||||
inline void Log::SetLogLevel(Logger::Level logLevel)
|
||||
{
|
||||
g_logLevel = static_cast<LogLevelInt>(logLevel);
|
||||
}
|
||||
inline void Log::SetLogLevel(Logger::Level logLevel) { g_logLevel = logLevel; }
|
||||
|
||||
void Log::Write(Logger::Level level, std::string const& message)
|
||||
{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user