diff --git a/dbms/src/IO/S3Common.cpp b/dbms/src/IO/S3Common.cpp index 6f6a304b481..5fabb181013 100644 --- a/dbms/src/IO/S3Common.cpp +++ b/dbms/src/IO/S3Common.cpp @@ -3,14 +3,58 @@ #if USE_AWS_S3 #include -#include #include #include #include #include +#include +#include +#include +namespace +{ +const std::pair & ConvertLogLevel(Aws::Utils::Logging::LogLevel log_level) +{ + static const std::unordered_map> 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 { @@ -25,10 +69,12 @@ namespace S3 { aws_options = Aws::SDKOptions {}; Aws::InitAPI(aws_options); + Aws::Utils::Logging::InitializeAWSLogging(std::make_shared()); } ClientFactory::~ClientFactory() { + Aws::Utils::Logging::ShutdownAWSLogging(); Aws::ShutdownAPI(aws_options); }