RDK Documentation (Open Sourced RDK Components)
AampLogManager.h
Go to the documentation of this file.
1 /*
2  * If not stated otherwise in this file or this component's license file the
3  * following copyright and licenses apply:
4  *
5  * Copyright 2020 RDK Management
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18 */
19 
20 #ifndef AAMPLOGMANAGER_H
21 #define AAMPLOGMANAGER_H
22 
23 /**
24  * @file AampLogManager.h
25  * @brief Log managed for Aamp
26  */
27 
28 #include <vector>
29 #include <memory.h>
30 
31 #include "AampMediaType.h"
32 
33 /*================================== AAMP Log Manager =========================================*/
34 
35 /**
36  * @brief Direct call for trace printf, can be enabled b defining TRACE here
37  */
38 #ifdef TRACE
39 #define traceprintf logprintf
40 #else
41 #define traceprintf(FORMAT, ...)
42 #endif
43 
44 /**
45  * @brief Macro for validating the log level to be enabled
46  *
47  * if mConfig or gpGlobalConfig is not initialized, skip logging
48  * if mconfig or gpGlobalConfig is initialized, check the LogLevel
49  */
50 #define AAMPLOG( MYLOGOBJ, LEVEL, LEVELSTR, FORMAT, ... ) \
51 do { \
52  int PLAYERID; \
53  if( MYLOGOBJ ) \
54  { \
55  if( !MYLOGOBJ->isLogLevelAllowed(LEVEL) ) break; \
56  PLAYERID = MYLOGOBJ->getPlayerId(); \
57  } \
58  else \
59  { \
60  if( !gpGlobalConfig->logging.isLogLevelAllowed(LEVEL) ) break; \
61  PLAYERID = -1; \
62  } \
63  logprintf_new( PLAYERID, LEVELSTR, __FUNCTION__, __LINE__, FORMAT, ##__VA_ARGS__); \
64 } while(0)
65 
66 /**
67  * @brief Macro for Triage Level Logging Support
68  */
69 #define AAMP_LOG_NETWORK_LATENCY mLogObj->LogNetworkLatency
70 #define AAMP_LOG_NETWORK_ERROR mLogObj->LogNetworkError
71 #define AAMP_LOG_DRM_ERROR gpGlobalConfig->logging.LogDRMError
72 #define AAMP_LOG_ABR_INFO mLogObj->LogABRInfo
73 #define AAMP_IS_LOG_WORTHY_ERROR mLogObj->isLogworthyErrorCode
74 
75 #define AAMPLOG_FAILOVER(FORMAT, ...) \
76  if (mLogObj && mLogObj->failover) { \
77  logprintf_new(mLogObj->getPlayerId(), "FAILOVER",__FUNCTION__, __LINE__, FORMAT, ##__VA_ARGS__); \
78  }
79 
80 /**
81  * @brief AAMP logging defines, this can be enabled through setLogLevel() as per the need
82  */
83 #define AAMPLOG_TRACE(FORMAT, ...) AAMPLOG(mLogObj,eLOGLEVEL_TRACE, "TRACE", FORMAT, ##__VA_ARGS__)
84 #define AAMPLOG_INFO(FORMAT, ...) AAMPLOG(mLogObj,eLOGLEVEL_INFO, "INFO", FORMAT, ##__VA_ARGS__)
85 #define AAMPLOG_WARN(FORMAT, ...) AAMPLOG(mLogObj,eLOGLEVEL_WARN, "WARN", FORMAT, ##__VA_ARGS__)
86 #define AAMPLOG_ERR(FORMAT, ...) AAMPLOG(mLogObj,eLOGLEVEL_ERROR, "ERROR", FORMAT, ##__VA_ARGS__)
87 
88 
89 /**
90  * @brief maximum supported mediatype for latency logging
91  */
92 #define MAX_SUPPORTED_LATENCY_LOGGING_TYPES (eMEDIATYPE_IFRAME+1)
93 
94 /**
95  * @brief Log level's of AAMP
96  */
98 {
99  eLOGLEVEL_TRACE, /**< Trace level */
100  eLOGLEVEL_INFO, /**< Info level */
101  eLOGLEVEL_WARN, /**< Warn level */
102  eLOGLEVEL_ERROR, /**< Error level */
103  eLOGLEVEL_FATAL /**< Fatal log level */
104 };
105 
106 /**
107  * @brief Log level network error enum
108  */
110 {
111  /* 0 */ AAMPNetworkErrorNone, /**< No network Error */
112  /* 1 */ AAMPNetworkErrorHttp, /**< HTTP error */
113  /* 2 */ AAMPNetworkErrorTimeout, /**< Timeout Error */
114  /* 3 */ AAMPNetworkErrorCurl /**< curl Error */
115 };
116 
117 /**
118  * @brief ABR type enum
119  */
121 {
122  /* 0 */ AAMPAbrBandwidthUpdate,
123  /* 1 */ AAMPAbrManifestDownloadFailed,
124  /* 2 */ AAMPAbrFragmentDownloadFailed,
125  /* 3 */ AAMPAbrUnifiedVideoEngine
126 };
127 
128 
129 /**
130  * @brief ABR info structure
131  */
133 {
134  AAMPAbrType abrCalledFor;
135  int currentProfileIndex;
136  int desiredProfileIndex;
137  long currentBandwidth;
138  long desiredBandwidth;
139  long networkBandwidth;
140  AAMPNetworkErrorType errorType;
141  int errorCode;
142 };
143 
144 
145 
146 /**
147  * @class AampLogManager
148  * @brief AampLogManager Class
149  */
151 {
152 public:
153 
154  bool info; /**< Info level*/
155  bool debug; /**< Debug logs*/
156  bool trace; /**< Trace level*/
157  bool gst; /**< Gstreamer logs*/
158  bool curl; /**< Curl logs*/
159  bool progress; /**< Download progress logs*/
160  bool failover; /**< server fail over logs*/
161  bool stream; /**< Display stream contents */
162  bool curlHeader; /**< Curl header logs*/
163  bool curlLicense; /**< Curl logs for License request*/
164  bool logMetadata; /**< Timed metadata logs*/
165  bool id3; /**< Display ID3 tag from stream logs */
166  static bool disableLogRedirection;
167  int mPlayerId; /**< Store PlayerId*/
168  /**
169  * @brief AampLogManager constructor
170  */
171  AampLogManager() : aampLoglevel(eLOGLEVEL_WARN), info(false), debug(false), trace(false), gst(false), curl(false), progress(false), failover(false), curlHeader(false),
172  logMetadata(false), curlLicense(false),stream(false), id3(false),mPlayerId(-1)
173  {
174  }
175 
176  /* ---------- Triage Level Logging Support ---------- */
177 
178  /**
179  * @fn LogNetworkLatency
180  *
181  * @param[in] url - content url
182  * @param[in] downloadTime - download time of the fragment or manifest
183  * @param[in] downloadThresholdTimeoutMs - specified download threshold time out value
184  * @param[in] type - media type
185  * @return void
186  */
187  void LogNetworkLatency(const char* url, int downloadTime, int downloadThresholdTimeoutMs, MediaType type);
188 
189  /**
190  * @fn LogNetworkError
191  *
192  * @param[in] url - content url
193  * @param[in] errorType - it can be http or curl errors
194  * @param[in] errorCode - it can be http error or curl error code
195  * @param[in] type - media type
196  * @return void
197  */
198  void LogNetworkError(const char* url, AAMPNetworkErrorType errorType, int errorCode, MediaType type);
199 
200  /**
201  * @fn ParseContentUrl
202  *
203  * @param[in] url - content url
204  * @param[out] contentType - it could be a manifest or other audio/video/iframe tracks
205  * @param[out] location - server location
206  * @param[out] symptom - issue exhibiting scenario for error case
207  * @param[in] type - media type
208  * @return void
209  */
210  void ParseContentUrl(const char* url, std::string& contentType, std::string& location, std::string& symptom, MediaType type);
211 
212  /**
213  * @fn LogDRMError
214  *
215  * @param[in] major - drm major error code
216  * @param[in] minor - drm minor error code
217  * @return void
218  */
219  void LogDRMError(int major, int minor);
220 
221  /**
222  * @fn LogABRInfo
223  *
224  * @param[in] pstAbrInfo - pointer to a structure which will have abr info to be logged
225  * @return void
226  */
227  void LogABRInfo(AAMPAbrInfo *pstAbrInfo);
228  /* !---------- Triage Level Logging Support ---------- */
229 
230  /**
231  * @fn isLogLevelAllowed
232  *
233  * @param[in] chkLevel - log level
234  * @retval true if the log level allowed for print mechanism
235  */
236  bool isLogLevelAllowed(AAMP_LogLevel chkLevel);
237  /**
238  * @brief Set PlayerId
239  *
240  * @param[in] playerId - Aamp Player Id
241  * @return void
242  */
243  void setPlayerId(int playerId) { mPlayerId = playerId;}
244  /**
245  * @brief Get PlayerId
246  *
247  * @return int - playerId
248  */
249  int getPlayerId() { return mPlayerId;}
250  /**
251  * @fn setLogLevel
252  *
253  * @param[in] newLevel - log level new value
254  * @return void
255  */
256  void setLogLevel(AAMP_LogLevel newLevel);
257 
258  /**
259  * @fn setLogAndCfgDirectory
260  */
261  void setLogAndCfgDirectory(char driveName);
262 
263  /**
264  * @fn isLogworthyErrorCode
265  * @param[in] errorCode - curl error
266  * @return true if it is not a curl error 23 and 42, bcasue those are not a real network errors.
267  */
268  bool isLogworthyErrorCode(int errorCode);
269 
270  /**
271  * @fn getAampCfgPath
272  */
273  const char* getAampCfgPath(void);
274 
275  /**
276  * @fn getAampCliCfgPath
277  */
278  const char* getAampCliCfgPath(void);
279 
280  /**
281  * @fn getHexDebugStr
282  */
283  static std::string getHexDebugStr(const std::vector<uint8_t>& data);
284 
285 private:
286  AAMP_LogLevel aampLoglevel;
287 };
288 
289 extern AampLogManager *mLogObj;
290 
291 /* Context-free utility function */
292 
293 /**
294  * @fn logprintf
295  * @param[in] format - printf style string
296  * @return void
297  */
298 extern void logprintf(const char *format, ...) __attribute__ ((format (printf, 1, 2)));;
299 /**
300  * @fn logprintf_new
301  * @param[in] format - printf style string
302  * @return void
303  */
304 extern void logprintf_new(int playerId,const char* levelstr,const char* file, int line,const char *format, ...) __attribute__ ((format (printf, 5, 6)));;
305 
306 /**
307  * @fn DumpBlob
308  *
309  * @param[in] ptr to the buffer
310  * @param[in] len length of buffer
311  *
312  * @return void
313  */
314 void DumpBlob(const unsigned char *ptr, size_t len);
315 
316 #endif /* AAMPLOGMANAGER_H */
AAMP_LogLevel
AAMP_LogLevel
Log level's of AAMP.
Definition: AampLogManager.h:97
AampLogManager::trace
bool trace
Definition: AampLogManager.h:156
AAMPAbrType
AAMPAbrType
ABR type enum.
Definition: AampLogManager.h:120
logprintf
void logprintf(const char *format,...) __attribute__((format(printf
Print logs to console / log fil.
Definition: aamplogging.cpp:432
AampLogManager::setLogAndCfgDirectory
void setLogAndCfgDirectory(char driveName)
Set log file and cfg directory index.
Definition: aamplogging.cpp:67
AampLogManager::LogNetworkError
void LogNetworkError(const char *url, AAMPNetworkErrorType errorType, int errorCode, MediaType type)
Print the network error level logging for triage purpose.
Definition: aamplogging.cpp:120
AampLogManager::stream
bool stream
Definition: AampLogManager.h:161
AampLogManager::AampLogManager
AampLogManager()
AampLogManager constructor.
Definition: AampLogManager.h:171
AampLogManager::failover
bool failover
Definition: AampLogManager.h:160
AampLogManager
AampLogManager Class.
Definition: AampLogManager.h:150
AampLogManager::LogABRInfo
void LogABRInfo(AAMPAbrInfo *pstAbrInfo)
Log ABR info for triage purpose.
Definition: aamplogging.cpp:355
AampLogManager::id3
bool id3
Definition: AampLogManager.h:165
AampLogManager::debug
bool debug
Definition: AampLogManager.h:155
AampLogManager::getAampCliCfgPath
const char * getAampCliCfgPath(void)
Get aampcli cfg directory.
Definition: aamplogging.cpp:85
AampLogManager::LogDRMError
void LogDRMError(int major, int minor)
Print the DRM error level logging for triage purpose.
Definition: aamplogging.cpp:267
AampLogManager::LogNetworkLatency
void LogNetworkLatency(const char *url, int downloadTime, int downloadThresholdTimeoutMs, MediaType type)
Print the network latency level logging for triage purpose.
Definition: aamplogging.cpp:105
AAMPNetworkErrorHttp
@ AAMPNetworkErrorHttp
Definition: AampLogManager.h:112
AampLogManager::info
bool info
Definition: AampLogManager.h:154
MediaType
MediaType
Media types.
Definition: AampMediaType.h:37
AAMPNetworkErrorType
AAMPNetworkErrorType
Log level network error enum.
Definition: AampLogManager.h:109
logprintf_new
void logprintf_new(int playerId, const char *levelstr, const char *file, int line, const char *format,...) __attribute__((format(printf
Print logs to console / log file.
Definition: aamplogging.cpp:482
AampLogManager::progress
bool progress
Definition: AampLogManager.h:159
AampLogManager::isLogworthyErrorCode
bool isLogworthyErrorCode(int errorCode)
Check curl error before log on console.
Definition: aamplogging.cpp:417
AampLogManager::getAampCfgPath
const char * getAampCfgPath(void)
Get aamp cfg directory.
Definition: aamplogging.cpp:77
AampLogManager::isLogLevelAllowed
bool isLogLevelAllowed(AAMP_LogLevel chkLevel)
To check the given log level is allowed to print mechanism.
Definition: aamplogging.cpp:50
eLOGLEVEL_WARN
@ eLOGLEVEL_WARN
Definition: AampLogManager.h:101
AampLogManager::curlHeader
bool curlHeader
Definition: AampLogManager.h:162
AAMPNetworkErrorCurl
@ AAMPNetworkErrorCurl
Definition: AampLogManager.h:114
AampLogManager::logMetadata
bool logMetadata
Definition: AampLogManager.h:164
AampLogManager::mPlayerId
int mPlayerId
Definition: AampLogManager.h:167
AampLogManager::curl
bool curl
Definition: AampLogManager.h:158
AampLogManager::getPlayerId
int getPlayerId()
Get PlayerId.
Definition: AampLogManager.h:249
AampLogManager::setPlayerId
void setPlayerId(int playerId)
Set PlayerId.
Definition: AampLogManager.h:243
AampLogManager::gst
bool gst
Definition: AampLogManager.h:157
eLOGLEVEL_ERROR
@ eLOGLEVEL_ERROR
Definition: AampLogManager.h:102
AAMPNetworkErrorTimeout
@ AAMPNetworkErrorTimeout
Definition: AampLogManager.h:113
AampMediaType.h
Media types representation.
AampLogManager::ParseContentUrl
void ParseContentUrl(const char *url, std::string &contentType, std::string &location, std::string &symptom, MediaType type)
To get the issue symptom based on the error type for triage purpose.
Definition: aamplogging.cpp:169
AampLogManager::getHexDebugStr
static std::string getHexDebugStr(const std::vector< uint8_t > &data)
Get a hex string representation of a vector of bytes.
Definition: aamplogging.cpp:93
eLOGLEVEL_TRACE
@ eLOGLEVEL_TRACE
Definition: AampLogManager.h:99
DumpBlob
void DumpBlob(const unsigned char *ptr, size_t len)
Compactly log blobs of binary data.
Definition: aamplogging.cpp:533
AAMPAbrInfo
ABR info structure.
Definition: AampLogManager.h:132
eLOGLEVEL_FATAL
@ eLOGLEVEL_FATAL
Definition: AampLogManager.h:103
AAMPNetworkErrorNone
@ AAMPNetworkErrorNone
Definition: AampLogManager.h:111
eLOGLEVEL_INFO
@ eLOGLEVEL_INFO
Definition: AampLogManager.h:100
AampLogManager::curlLicense
bool curlLicense
Definition: AampLogManager.h:163
AampLogManager::setLogLevel
void setLogLevel(AAMP_LogLevel newLevel)
Set the log level for print mechanism.
Definition: aamplogging.cpp:58