Logging - AWS SDK for C++


The AWS SDK for C++ includes configurable logging that generates a record of actions performed by the SDK during execution. To enable logging, set the LogLevel of SDKOptions to the appropriate verbosity for your application.

Aws::SDKOptions options; options.loggingOptions.logLevel = Aws::Utils::Logging::LogLevel::Info;

There are seven levels of verbosity to choose from. The default value is Off and no logs will be generated. Trace will generate the most level of detail, and Fatal will generate the least messages reporting only fatal error conditions.

Once logging is enabled in your application, the SDK will generate log files in your executable directory following the default naming pattern of aws_sdk_<date>.log. The log file generated by the prefix-naming option rolls over once per hour to allow for archiving or deleting log files.

The later versions of the SDK increasingly depend on the underlying AWS Common Runtime (CRT) libraries. These libraries provide common functionality and basic operations among SDKs. All log messages from the CRT libraries will be redirected to the SDK for C++ by default. The log level and logging system you specify for the SDK for C++ also applies to the CRT.

In the previous example, the CRT will inherit LogLevel::Info and also log messages at the Info level to the same file.

You can independently control the logging for the CRT libraries, either by redirecting its output to a separate log file, or by setting a different log level for messages from the CRT. Often it can be beneficial to reduce the verbosity of the CRT libraries so that they don’t overwhelm the logs. For example, the log level for only the CRT output can be set to Warn as follows:

options.loggingOptions.crt_logger_create_fn = [](){ return Aws::MakeShared<Aws::Utils::Logging::DefaultCRTLogSystem>("CRTLogSystem", Aws::Utils::Logging::LogLevel::Warn); };

By optionally using the method InitializeAWSLogging, you can control the verbosity level and the log output of the DefaultLogSystem. You can configure the log filename prefix, or redirect the output to a stream instead of a file.

Aws::Utils::Logging::InitializeAWSLogging( Aws::MakeShared<Aws::Utils::Logging::DefaultLogSystem>( "RunUnitTests", Aws::Utils::Logging::LogLevel::Trace, "aws_sdk_"));

Alternatively, instead of using the DefaultLogSystem, you can also use this method to provide your own logging implementation.


If you call method InitializeAWSLogging, free resources at the end of your program by calling ShutdownAWSLogging.


Example integration test with logging

#include <aws/external/gtest.h> #include <aws/core/utils/memory/stl/AWSString.h> #include <aws/core/utils/logging/DefaultLogSystem.h> #include <aws/core/utils/logging/AWSLogging.h> #include <iostream> int main(int argc, char** argv) { Aws::Utils::Logging::InitializeAWSLogging( Aws::MakeShared<Aws::Utils::Logging::DefaultLogSystem>( "RunUnitTests", Aws::Utils::Logging::LogLevel::Trace, "aws_sdk_")); ::testing::InitGoogleTest(&argc, argv); int exitCode = RUN_ALL_TESTS(); Aws::Utils::Logging::ShutdownAWSLogging(); return exitCode; }