mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-26 09:32:01 +00:00
Attach AWS SDK logging to CH logging system
This commit is contained in:
parent
94b98e7f29
commit
bdb9156843
@ -3,14 +3,58 @@
|
|||||||
#if USE_AWS_S3
|
#if USE_AWS_S3
|
||||||
|
|
||||||
#include <IO/S3Common.h>
|
#include <IO/S3Common.h>
|
||||||
#include <IO/WriteHelpers.h>
|
|
||||||
#include <IO/WriteBufferFromString.h>
|
#include <IO/WriteBufferFromString.h>
|
||||||
|
|
||||||
#include <regex>
|
#include <regex>
|
||||||
#include <aws/s3/S3Client.h>
|
#include <aws/s3/S3Client.h>
|
||||||
#include <aws/core/auth/AWSCredentialsProvider.h>
|
#include <aws/core/auth/AWSCredentialsProvider.h>
|
||||||
|
#include <aws/core/utils/logging/LogSystemInterface.h>
|
||||||
|
#include <aws/core/utils/logging/LogMacros.h>
|
||||||
|
#include <common/logger_useful.h>
|
||||||
|
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
const std::pair<LogsLevel, Message::Priority> & ConvertLogLevel(Aws::Utils::Logging::LogLevel log_level)
|
||||||
|
{
|
||||||
|
static const std::unordered_map<Aws::Utils::Logging::LogLevel, std::pair<LogsLevel, Message::Priority>> mapping = {
|
||||||
|
{Aws::Utils::Logging::LogLevel::Off, {LogsLevel::none, Message::PRIO_FATAL}},
|
||||||
|
{Aws::Utils::Logging::LogLevel::Fatal, {LogsLevel::error, Message::PRIO_FATAL}},
|
||||||
|
{Aws::Utils::Logging::LogLevel::Error, {LogsLevel::error, Message::PRIO_ERROR}},
|
||||||
|
{Aws::Utils::Logging::LogLevel::Warn, {LogsLevel::warning, Message::PRIO_WARNING}},
|
||||||
|
{Aws::Utils::Logging::LogLevel::Info, {LogsLevel::information, Message::PRIO_INFORMATION}},
|
||||||
|
{Aws::Utils::Logging::LogLevel::Debug, {LogsLevel::debug, Message::PRIO_DEBUG}},
|
||||||
|
{Aws::Utils::Logging::LogLevel::Trace, {LogsLevel::trace, Message::PRIO_TRACE}},
|
||||||
|
};
|
||||||
|
return mapping.at(log_level);
|
||||||
|
}
|
||||||
|
|
||||||
|
class AWSLogger : public Aws::Utils::Logging::LogSystemInterface
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
~AWSLogger() final = default;
|
||||||
|
|
||||||
|
Aws::Utils::Logging::LogLevel GetLogLevel() const final { return Aws::Utils::Logging::LogLevel::Trace; }
|
||||||
|
|
||||||
|
void Log(Aws::Utils::Logging::LogLevel log_level, const char * tag, const char * format_str, ...) final
|
||||||
|
{
|
||||||
|
auto & [level, prio] = ConvertLogLevel(log_level);
|
||||||
|
LOG_SIMPLE(log, std::string(tag) + ": " + format_str, level, prio);
|
||||||
|
}
|
||||||
|
|
||||||
|
void LogStream(Aws::Utils::Logging::LogLevel log_level, const char * tag, const Aws::OStringStream & message_stream) final
|
||||||
|
{
|
||||||
|
auto & [level, prio] = ConvertLogLevel(log_level);
|
||||||
|
LOG_SIMPLE(log, std::string(tag) + ": " + message_stream.str(), level, prio);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Flush() final {}
|
||||||
|
|
||||||
|
private:
|
||||||
|
Poco::Logger * log = &Poco::Logger::get("AwsClient");
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
namespace DB
|
namespace DB
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -25,10 +69,12 @@ namespace S3
|
|||||||
{
|
{
|
||||||
aws_options = Aws::SDKOptions {};
|
aws_options = Aws::SDKOptions {};
|
||||||
Aws::InitAPI(aws_options);
|
Aws::InitAPI(aws_options);
|
||||||
|
Aws::Utils::Logging::InitializeAWSLogging(std::make_shared<AWSLogger>());
|
||||||
}
|
}
|
||||||
|
|
||||||
ClientFactory::~ClientFactory()
|
ClientFactory::~ClientFactory()
|
||||||
{
|
{
|
||||||
|
Aws::Utils::Logging::ShutdownAWSLogging();
|
||||||
Aws::ShutdownAPI(aws_options);
|
Aws::ShutdownAPI(aws_options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user