Remove Azure::Core::Diagnostics::Logger::Listener typedef (#2282)

This commit is contained in:
Anton Kolesnyk 2021-05-18 18:43:11 +00:00 committed by GitHub
parent d8214af143
commit 898a8aee84
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 26 additions and 22 deletions

View File

@ -12,6 +12,7 @@
- Removed `Context::GetApplicationContext()` in favor of a new static data member `Context::ApplicationContext`.
- Renamed `Request::IsDownloadViaStream()` to `ShouldBufferResponse()`.
- Removed the `Azure::Core::Http::Request` ctor overload that takes both a `bodyStream` and a `bufferedDownload` boolean since it is not useful.
- Removed the `Azure::Core::Diagnostics::Logger::Listener` typedef.
### Bug Fixes

View File

@ -38,21 +38,13 @@ namespace Azure { namespace Core { namespace Diagnostics {
Error = 4,
};
/**
* @brief A callback function to receive Azure SDK log messages.
*
* @param level The log message level.
* @param message The log message text.
*/
typedef std::function<void(Level level, std::string const& message)> Listener;
/**
* @brief Sets the function that will be invoked to report an Azure SDK log message.
*
* @param listener A callback function that will be invoked when the SDK reports a log message.
* If `nullptr`, no function will be invoked.
*/
static void SetListener(Listener listener);
static void SetListener(std::function<void(Level level, std::string const& message)> listener);
/**
* @brief Sets the log message level an application is interested in receiving.

View File

@ -123,7 +123,8 @@ Logger::Level EnvironmentLogLevelListener::GetLogLevel(Logger::Level defaultValu
return envLogLevelPtr ? *envLogLevelPtr : defaultValue;
}
Logger::Listener EnvironmentLogLevelListener::GetLogListener()
std::function<void(Logger::Level level, std::string const& message)>
EnvironmentLogLevelListener::GetLogListener()
{
bool const isEnvLogLevelSet = GetEnvironmentLogLevel() != nullptr;
if (!isEnvLogLevelSet)
@ -131,13 +132,14 @@ Logger::Listener EnvironmentLogLevelListener::GetLogListener()
return nullptr;
}
static Logger::Listener const consoleLogger = [](auto level, auto message) {
std::cerr << '['
<< Azure::DateTime(std::chrono::system_clock::now())
.ToString(
DateTime::DateFormat::Rfc3339, DateTime::TimeFractionFormat::AllDigits)
<< "] " << LogLevelToConsoleString(level) << " : " << message << std::endl;
};
static std::function<void(Logger::Level level, std::string const& message)> const consoleLogger =
[](auto level, auto message) {
std::cerr << '['
<< Azure::DateTime(std::chrono::system_clock::now())
.ToString(
DateTime::DateFormat::Rfc3339, DateTime::TimeFractionFormat::AllDigits)
<< "] " << LogLevelToConsoleString(level) << " : " << message << std::endl;
};
return consoleLogger;
}

View File

@ -14,7 +14,8 @@ using namespace Azure::Core::Diagnostics::_internal;
namespace {
static std::shared_timed_mutex g_logListenerMutex;
static Logger::Listener g_logListener(_detail::EnvironmentLogLevelListener::GetLogListener());
static std::function<void(Logger::Level level, std::string const& message)> g_logListener(
_detail::EnvironmentLogLevelListener::GetLogListener());
} // namespace
std::atomic<bool> Log::g_isLoggingEnabled(
@ -42,7 +43,8 @@ void Log::Write(Logger::Level level, std::string const& message)
}
}
void Logger::SetListener(Logger::Listener listener)
void Logger::SetListener(
std::function<void(Logger::Level level, std::string const& message)> listener)
{
std::unique_lock<std::shared_timed_mutex> loggerLock(g_logListenerMutex);
g_logListener = std::move(listener);

View File

@ -25,7 +25,7 @@ namespace Azure { namespace Core { namespace Diagnostics { namespace _detail {
public:
static Logger::Level GetLogLevel(Logger::Level defaultValue);
static Logger::Listener GetLogListener();
static std::function<void(Logger::Level level, std::string const& message)> GetLogListener();
};
#if (defined(WINAPI_PARTITION_DESKTOP) && !WINAPI_PARTITION_DESKTOP) // See azure/core/platform.hpp
@ -35,6 +35,10 @@ namespace Azure { namespace Core { namespace Diagnostics { namespace _detail {
return defaultValue;
}
inline Logger::Listener EnvironmentLogLevelListener::GetLogListener() { return nullptr; }
inline std::function<void(Logger::Level level, std::string const& message)>
EnvironmentLogLevelListener::GetLogListener()
{
return nullptr;
}
#endif
}}}} // namespace Azure::Core::Diagnostics::_detail

View File

@ -37,7 +37,10 @@ TEST(SimplifiedHeader, core)
EXPECT_NO_THROW(Azure::Core::Cryptography::Md5Hash m);
EXPECT_NO_THROW(Azure::Core::Http::RawResponse r(
1, 1, Azure::Core::Http::HttpStatusCode::Accepted, "phrase"));
EXPECT_NO_THROW(Azure::Core::Diagnostics::Logger::Listener ll = nullptr);
EXPECT_NO_THROW({
Azure::Core::Diagnostics::Logger::Level ll;
(void)ll;
});
EXPECT_NO_THROW(Azure::MatchConditions mc);
EXPECT_NO_THROW(Azure::ModifiedConditions mc);
EXPECT_NO_THROW(Azure::Nullable<int> n);