AlexaClientSDK  3.0.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
LogEntry.h
Go to the documentation of this file.
1 /*
2  * Copyright 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 #ifndef ALEXA_CLIENT_SDK_AVSCOMMON_UTILS_INCLUDE_AVSCOMMON_UTILS_LOGGER_LOGENTRY_H_
17 #define ALEXA_CLIENT_SDK_AVSCOMMON_UTILS_INCLUDE_AVSCOMMON_UTILS_LOGGER_LOGENTRY_H_
18 
19 #include <algorithm>
20 #include <cctype>
21 #include <functional>
22 #include <sstream>
23 #include <string>
24 
26 
27 namespace alexaClientSDK {
28 namespace avsCommon {
29 namespace utils {
30 namespace logger {
31 
33 class LogEntry {
34 public:
43  LogEntry(const char* source, const char* event);
44 
52  LogEntry(const std::string& source, const char* event);
53 
60  LogEntry(const std::string& source, const std::string& event);
61 
70  template <typename ValueType>
71  LogEntry& d(const std::string& key, const ValueType& value);
72 
81  LogEntry& d(const char* key, const char* value);
82 
91  LogEntry& d(const char* key, char* value);
92 
101  LogEntry& d(const char* key, const std::string& value);
102 
111  LogEntry& d(const char* key, bool value);
112 
121  template <typename ValueType>
122  LogEntry& d(const char* key, const ValueType& value);
123 
133  template <typename ValueType>
134  LogEntry& sensitive(const char* key, const ValueType& value);
135 
147  LogEntry& obfuscatePrivateData(const char* key, const std::string& value);
148 
158  LogEntry& m(const char* message);
159 
168  LogEntry& m(const std::string& message);
169 
180  template <typename PtrType>
181  LogEntry& p(const char* key, const std::shared_ptr<PtrType>& ptr);
182 
193  LogEntry& p(const char* key, const void* ptr);
194 
201  const char* c_str() const;
202 
203 private:
205  void prefixKeyValuePair();
206 
208  void prefixMessage();
209 
218  void appendEscapedString(const char* in);
219 
221  static const char KEY_VALUE_SEPARATOR = '=';
222 
224  bool m_hasMetadata;
225 
227  LogEntryStream m_stream;
228 };
229 
230 template <typename ValueType>
231 inline LogEntry& LogEntry::d(const std::string& key, const ValueType& value) {
232  return d(key.c_str(), value);
233 }
234 
235 template <typename ValueType>
236 inline LogEntry& LogEntry::d(const char* key, const ValueType& value) {
237  prefixKeyValuePair();
238  m_stream << key << KEY_VALUE_SEPARATOR << value;
239  return *this;
240 }
241 
242 inline LogEntry& LogEntry::d(const char* key, char* value) {
243  return d(key, const_cast<const char*>(value));
244 }
245 
246 template <typename PtrType>
247 inline LogEntry& LogEntry::p(const char* key, const std::shared_ptr<PtrType>& ptr) {
248  return d(key, ptr.get());
249 }
250 
251 // Define ACSDK_EMIT_SENSITIVE_LOGS if you want to include sensitive data in log output.
252 #ifdef ACSDK_EMIT_SENSITIVE_LOGS
253 
254 template <typename ValueType>
255 inline LogEntry& LogEntry::sensitive(const char* key, const ValueType& value) {
256  return d(key, value);
257 }
258 #else
259 template <typename ValueType>
260 inline LogEntry& LogEntry::sensitive(const char*, const ValueType&) {
261  return *this;
262 }
263 #endif
264 
265 } // namespace logger
266 } // namespace utils
267 } // namespace avsCommon
268 } // namespace alexaClientSDK
269 
270 #endif // ALEXA_CLIENT_SDK_AVSCOMMON_UTILS_INCLUDE_AVSCOMMON_UTILS_LOGGER_LOGENTRY_H_
LogEntry & obfuscatePrivateData(const char *key, const std::string &value)
::std::string string
Definition: gtest-port.h:1097
LogEntry & p(const char *key, const std::shared_ptr< PtrType > &ptr)
Definition: LogEntry.h:247
const char * c_str() const
LogEntry & sensitive(const char *key, const ValueType &value)
Definition: LogEntry.h:260
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
LogEntry(const char *source, const char *event)
LogEntry & d(const std::string &key, const ValueType &value)
Definition: LogEntry.h:231
LogEntry & m(const char *message)
Definition: LogEntryStream.h:31
tuple message
Definition: gtest_output_test.py:331
static const std::string key
The database key to be used by the protocol given the METADATA object.
Definition: SharedAVSSettingProtocolTest.cpp:58
LogEntry is used to compile the log entry text to log via Logger.
Definition: LogEntry.h:33

AlexaClientSDK 3.0.0 - Copyright 2016-2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. Licensed under the Apache License, Version 2.0