AWS SDK for C++

AWS SDK for C++ Version 1.11.606

Loading...
Searching...
No Matches
LogMacros.h
1
6#pragma once
7
8#include <aws/core/Core_EXPORTS.h>
9
10#include <aws/core/utils/logging/LogLevel.h>
11#include <aws/core/utils/logging/AWSLogging.h>
12#include <aws/core/utils/logging/LogSystemInterface.h>
13#include <aws/core/utils/memory/stl/AWSStringStream.h>
14
15// While macros are usually grotty, using them here lets us have a simple function call interface for logging that
16//
17// (1) Can be compiled out completely, so you don't even have to pay the cost to check the log level (which will be a virtual function call and a std::atomic<> read) if you don't want any AWS logging
18// (2) If you use logging and the log statement doesn't pass the conditional log filter level, not only do you not pay the cost of building the log string, you don't pay the cost for allocating or
19// getting any of the values used in building the log string, as they're in a scope (if-statement) that never gets entered.
20
21#ifdef DISABLE_AWS_LOGGING
22
23 #define AWS_LOG(level, tag, ...)
24 #define AWS_LOG_FATAL(tag, ...)
25 #define AWS_LOG_ERROR(tag, ...)
26 #define AWS_LOG_WARN(tag, ...)
27 #define AWS_LOG_INFO(tag, ...)
28 #define AWS_LOG_DEBUG(tag, ...)
29 #define AWS_LOG_TRACE(tag, ...)
30 #define AWS_LOG_FLUSH()
31
32 #define AWS_LOGSTREAM(level, tag, streamExpression)
33 #define AWS_LOGSTREAM_FATAL(tag, streamExpression)
34 #define AWS_LOGSTREAM_ERROR(tag, streamExpression)
35 #define AWS_LOGSTREAM_WARN(tag, streamExpression)
36 #define AWS_LOGSTREAM_INFO(tag, streamExpression)
37 #define AWS_LOGSTREAM_DEBUG(tag, streamExpression)
38 #define AWS_LOGSTREAM_TRACE(tag, streamExpression)
39 #define AWS_LOGSTREAM_FLUSH()
40
41#else
42
43 #define AWS_LOG_FLUSH() \
44 { \
45 Aws::Utils::Logging::LogSystemInterface* logSystem = Aws::Utils::Logging::GetLogSystem(); \
46 if ( logSystem ) \
47 { \
48 logSystem->Flush(); \
49 } \
50 }
51
52 #define AWS_LOG(level, tag, ...) \
53 { \
54 Aws::Utils::Logging::LogSystemInterface* logSystem = Aws::Utils::Logging::GetLogSystem(); \
55 if ( logSystem && logSystem->GetLogLevel() >= level ) \
56 { \
57 logSystem->Log(level, tag, __VA_ARGS__); \
58 } \
59 }
60
61 #define AWS_LOG_FATAL(tag, ...) AWS_LOG(Aws::Utils::Logging::LogLevel::Fatal, tag, __VA_ARGS__)
62 #define AWS_LOG_ERROR(tag, ...) AWS_LOG(Aws::Utils::Logging::LogLevel::Error, tag, __VA_ARGS__)
63 #define AWS_LOG_WARN(tag, ...) AWS_LOG(Aws::Utils::Logging::LogLevel::Warn, tag, __VA_ARGS__)
64 #define AWS_LOG_INFO(tag, ...) AWS_LOG(Aws::Utils::Logging::LogLevel::Info, tag, __VA_ARGS__)
65 #define AWS_LOG_DEBUG(tag, ...) AWS_LOG(Aws::Utils::Logging::LogLevel::Debug, tag, __VA_ARGS__)
66 #define AWS_LOG_TRACE(tag, ...) AWS_LOG(Aws::Utils::Logging::LogLevel::Trace, tag, __VA_ARGS__)
67
68 #define AWS_LOGSTREAM(level, tag, streamExpression) \
69 { \
70 Aws::Utils::Logging::LogSystemInterface* logSystem = Aws::Utils::Logging::GetLogSystem(); \
71 if ( logSystem && logSystem->GetLogLevel() >= level ) \
72 { \
73 Aws::OStringStream logStream; \
74 logStream << streamExpression; \
75 logSystem->LogStream( level, tag, logStream ); \
76 } \
77 }
78
79 #define AWS_LOGSTREAM_FATAL(tag, streamExpression) \
80 do { \
81 AWS_LOGSTREAM(Aws::Utils::Logging::LogLevel::Fatal, tag, streamExpression) \
82 AWS_LOG_FLUSH() \
83 } while(0)
84 #define AWS_LOGSTREAM_ERROR(tag, streamExpression) AWS_LOGSTREAM(Aws::Utils::Logging::LogLevel::Error, tag, streamExpression)
85 #define AWS_LOGSTREAM_WARN(tag, streamExpression) AWS_LOGSTREAM(Aws::Utils::Logging::LogLevel::Warn, tag, streamExpression)
86 #define AWS_LOGSTREAM_INFO(tag, streamExpression) AWS_LOGSTREAM(Aws::Utils::Logging::LogLevel::Info, tag, streamExpression)
87 #define AWS_LOGSTREAM_DEBUG(tag, streamExpression) AWS_LOGSTREAM(Aws::Utils::Logging::LogLevel::Debug, tag, streamExpression)
88 #define AWS_LOGSTREAM_TRACE(tag, streamExpression) AWS_LOGSTREAM(Aws::Utils::Logging::LogLevel::Trace, tag, streamExpression)
89 #define AWS_LOGSTREAM_FLUSH() AWS_LOG_FLUSH()
90
91#endif // DISABLE_AWS_LOGGING