AWS SDK for C++  0.12.9
AWS SDK for C++
LogMacros.h
Go to the documentation of this file.
1 /*
2  * Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License").
5  * You may not use this file except in compliance with the License.
6  * A copy of the License is located at
7  *
8  * http://aws.amazon.com/apache2.0
9  *
10  * or in the "license" file accompanying this file. This file is distributed
11  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12  * express or implied. See the License for the specific language governing
13  * permissions and limitations under the License.
14  */
15 
16 #pragma once
17 
18 #include <aws/core/Core_EXPORTS.h>
19 
24 
25 // While macros are usually grotty, using them here lets us have a simple function call interface for logging that
26 //
27 // (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
28 // (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
29 // getting any of the values used in building the log string, as they're in a scope (if-statement) that never gets entered.
30 
31 #ifdef DISABLE_AWS_LOGGING
32 
33  #define AWS_LOG(level, tag, ...)
34  #define AWS_LOG_FATAL(tag, ...)
35  #define AWS_LOG_ERROR(tag, ...)
36  #define AWS_LOG_WARN(tag, ...)
37  #define AWS_LOG_INFO(tag, ...)
38  #define AWS_LOG_DEBUG(tag, ...)
39  #define AWS_LOG_TRACE(tag, ...)
40 
41  #define AWS_LOGSTREAM(level, tag, streamExpression)
42  #define AWS_LOGSTREAM_FATAL(tag, streamExpression)
43  #define AWS_LOGSTREAM_ERROR(tag, streamExpression)
44  #define AWS_LOGSTREAM_WARN(tag, streamExpression)
45  #define AWS_LOGSTREAM_INFO(tag, streamExpression)
46  #define AWS_LOGSTREAM_DEBUG(tag, streamExpression)
47  #define AWS_LOGSTREAM_TRACE(tag, streamExpression)
48 
49 #else
50 
51  #define AWS_LOG(level, tag, ...) \
52  { \
53  Aws::Utils::Logging::LogSystemInterface* logSystem = Aws::Utils::Logging::GetLogSystem(); \
54  if ( logSystem && logSystem->GetLogLevel() >= level ) \
55  { \
56  logSystem->Log(level, tag, __VA_ARGS__); \
57  } \
58  }
59 
60  #define AWS_LOG_FATAL(tag, ...) \
61  { \
62  Aws::Utils::Logging::LogSystemInterface* logSystem = Aws::Utils::Logging::GetLogSystem(); \
63  if ( logSystem && logSystem->GetLogLevel() >= Aws::Utils::Logging::LogLevel::Fatal ) \
64  { \
65  logSystem->Log(Aws::Utils::Logging::LogLevel::Fatal, tag, __VA_ARGS__); \
66  } \
67  }
68 
69  #define AWS_LOG_ERROR(tag, ...) \
70  { \
71  Aws::Utils::Logging::LogSystemInterface* logSystem = Aws::Utils::Logging::GetLogSystem(); \
72  if ( logSystem && logSystem->GetLogLevel() >= Aws::Utils::Logging::LogLevel::Error ) \
73  { \
74  logSystem->Log(Aws::Utils::Logging::LogLevel::Error, tag, __VA_ARGS__); \
75  } \
76  }
77 
78  #define AWS_LOG_WARN(tag, ...) \
79  { \
80  Aws::Utils::Logging::LogSystemInterface* logSystem = Aws::Utils::Logging::GetLogSystem(); \
81  if ( logSystem && logSystem->GetLogLevel() >= Aws::Utils::Logging::LogLevel::Warn ) \
82  { \
83  logSystem->Log(Aws::Utils::Logging::LogLevel::Warn, tag, __VA_ARGS__); \
84  } \
85  }
86 
87  #define AWS_LOG_INFO(tag, ...) \
88  { \
89  Aws::Utils::Logging::LogSystemInterface* logSystem = Aws::Utils::Logging::GetLogSystem(); \
90  if ( logSystem && logSystem->GetLogLevel() >= Aws::Utils::Logging::LogLevel::Info ) \
91  { \
92  logSystem->Log(Aws::Utils::Logging::LogLevel::Info, tag, __VA_ARGS__); \
93  } \
94  }
95 
96  #define AWS_LOG_DEBUG(tag, ...) \
97  { \
98  Aws::Utils::Logging::LogSystemInterface* logSystem = Aws::Utils::Logging::GetLogSystem(); \
99  if ( logSystem && logSystem->GetLogLevel() >= Aws::Utils::Logging::LogLevel::Debug ) \
100  { \
101  logSystem->Log(Aws::Utils::Logging::LogLevel::Debug, tag, __VA_ARGS__); \
102  } \
103  }
104 
105  #define AWS_LOG_TRACE(tag, ...) \
106  { \
107  Aws::Utils::Logging::LogSystemInterface* logSystem = Aws::Utils::Logging::GetLogSystem(); \
108  if ( logSystem && logSystem->GetLogLevel() >= Aws::Utils::Logging::LogLevel::Trace ) \
109  { \
110  logSystem->Log(Aws::Utils::Logging::LogLevel::Trace, tag, __VA_ARGS__); \
111  } \
112  }
113 
114  #define AWS_LOGSTREAM(level, tag, streamExpression) \
115  { \
116  Aws::Utils::Logging::LogSystemInterface* logSystem = Aws::Utils::Logging::GetLogSystem(); \
117  if ( logSystem && logSystem->GetLogLevel() >= level ) \
118  { \
119  Aws::OStringStream logStream; \
120  logStream << streamExpression; \
121  logSystem->LogStream( logLevel, tag, logStream ); \
122  } \
123  }
124 
125  #define AWS_LOGSTREAM_FATAL(tag, streamExpression) \
126  { \
127  Aws::Utils::Logging::LogSystemInterface* logSystem = Aws::Utils::Logging::GetLogSystem(); \
128  if ( logSystem && logSystem->GetLogLevel() >= Aws::Utils::Logging::LogLevel::Fatal ) \
129  { \
130  Aws::OStringStream logStream; \
131  logStream << streamExpression; \
132  logSystem->LogStream( Aws::Utils::Logging::LogLevel::Fatal, tag, logStream ); \
133  } \
134  }
135 
136  #define AWS_LOGSTREAM_ERROR(tag, streamExpression) \
137  { \
138  Aws::Utils::Logging::LogSystemInterface* logSystem = Aws::Utils::Logging::GetLogSystem(); \
139  if ( logSystem && logSystem->GetLogLevel() >= Aws::Utils::Logging::LogLevel::Error ) \
140  { \
141  Aws::OStringStream logStream; \
142  logStream << streamExpression; \
143  logSystem->LogStream( Aws::Utils::Logging::LogLevel::Error, tag, logStream ); \
144  } \
145  }
146 
147  #define AWS_LOGSTREAM_WARN(tag, streamExpression) \
148  { \
149  Aws::Utils::Logging::LogSystemInterface* logSystem = Aws::Utils::Logging::GetLogSystem(); \
150  if ( logSystem && logSystem->GetLogLevel() >= Aws::Utils::Logging::LogLevel::Warn ) \
151  { \
152  Aws::OStringStream logStream; \
153  logStream << streamExpression; \
154  logSystem->LogStream( Aws::Utils::Logging::LogLevel::Warn, tag, logStream ); \
155  } \
156  }
157 
158  #define AWS_LOGSTREAM_INFO(tag, streamExpression) \
159  { \
160  Aws::Utils::Logging::LogSystemInterface* logSystem = Aws::Utils::Logging::GetLogSystem(); \
161  if ( logSystem && logSystem->GetLogLevel() >= Aws::Utils::Logging::LogLevel::Info ) \
162  { \
163  Aws::OStringStream logStream; \
164  logStream << streamExpression; \
165  logSystem->LogStream( Aws::Utils::Logging::LogLevel::Info, tag, logStream ); \
166  } \
167  }
168 
169  #define AWS_LOGSTREAM_DEBUG(tag, streamExpression) \
170  { \
171  Aws::Utils::Logging::LogSystemInterface* logSystem = Aws::Utils::Logging::GetLogSystem(); \
172  if ( logSystem && logSystem->GetLogLevel() >= Aws::Utils::Logging::LogLevel::Debug ) \
173  { \
174  Aws::OStringStream logStream; \
175  logStream << streamExpression; \
176  logSystem->LogStream( Aws::Utils::Logging::LogLevel::Debug, tag, logStream ); \
177  } \
178  }
179 
180  #define AWS_LOGSTREAM_TRACE(tag, streamExpression) \
181  { \
182  Aws::Utils::Logging::LogSystemInterface* logSystem = Aws::Utils::Logging::GetLogSystem(); \
183  if ( logSystem && logSystem->GetLogLevel() >= Aws::Utils::Logging::LogLevel::Trace ) \
184  { \
185  Aws::OStringStream logStream; \
186  logStream << streamExpression; \
187  logSystem->LogStream( Aws::Utils::Logging::LogLevel::Trace, tag, logStream ); \
188  } \
189  }
190 
191 #endif // DISABLE_AWS_LOGGING