RDK Documentation (Open Sourced RDK Components)
FakeAampLogManager.cpp
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 2022 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 #include <cstdarg>
21 #include <iostream>
22 #include <sstream>
23 #include <iomanip>
24 #include <algorithm>
25 #include <unordered_map>
26 #include <memory>
27 
28 #include "priv_aamp.h"
29 #include "AampLogManager.h"
30 
31 //Enable the define below to get AAMP logging out when running tests
32 //#define ENABLE_LOGGING
33 #define TEST_LOG_LEVEL eLOGLEVEL_TRACE
34 
36 {
37  return chkLevel >= TEST_LOG_LEVEL;
38 }
39 
40 std::string AampLogManager::getHexDebugStr(const std::vector<uint8_t>& data)
41 {
42  std::ostringstream hexSs;
43  hexSs << "0x";
44  hexSs << std::hex << std::uppercase << std::setfill('0');
45  std::for_each(data.cbegin(), data.cend(), [&](int c) { hexSs << std::setw(2) << c; });
46  return hexSs.str();
47 }
48 
50 {
51 }
52 
53 void logprintf(const char *format, ...)
54 {
55 #ifdef ENABLE_LOGGING
56  int len = 0;
57  va_list args;
58  va_start(args, format);
59 
60  char gDebugPrintBuffer[MAX_DEBUG_LOG_BUFF_SIZE];
61  len = snprintf(gDebugPrintBuffer, sizeof(gDebugPrintBuffer), "[AAMP-PLAYER]");
62  vsnprintf(gDebugPrintBuffer+len, MAX_DEBUG_LOG_BUFF_SIZE-len, format, args);
63  gDebugPrintBuffer[(MAX_DEBUG_LOG_BUFF_SIZE-1)] = 0;
64 
65  std::cout << gDebugPrintBuffer << std::endl;
66 
67  va_end(args);
68 #endif
69 }
70 
71 void logprintf_new(int playerId, const char* levelstr, const char* file, int line, const char *format, ...)
72 {
73 #ifdef ENABLE_LOGGING
74  int len = 0;
75  va_list args;
76  va_start(args, format);
77 
78  char gDebugPrintBuffer[MAX_DEBUG_LOG_BUFF_SIZE];
79  len = snprintf(gDebugPrintBuffer, sizeof(gDebugPrintBuffer), "[AAMP-PLAYER][%d][%s][%s][%d]", playerId, levelstr, file, line);
80  vsnprintf(gDebugPrintBuffer+len, MAX_DEBUG_LOG_BUFF_SIZE-len, format, args);
81  gDebugPrintBuffer[(MAX_DEBUG_LOG_BUFF_SIZE-1)] = 0;
82 
83  std::cout << gDebugPrintBuffer << std::endl;
84 
85  va_end(args);
86 #endif
87 }
88 
89 void DumpBlob(const unsigned char *ptr, size_t len)
90 {
91 }
92 
93 /**
94  * @brief Print the network error level logging for triage purpose
95  */
96 void AampLogManager::LogNetworkError(const char* url, AAMPNetworkErrorType errorType, int errorCode, MediaType type)
97 {
98 }
99 
100 /**
101  * @brief Print the network latency level logging for triage purpose
102  */
103 void AampLogManager::LogNetworkLatency(const char* url, int downloadTime, int downloadThresholdTimeoutMs, MediaType type)
104 {
105 }
106 
107 /**
108  * @brief Check curl error before log on console
109  */
110 bool AampLogManager::isLogworthyErrorCode(int errorCode)
111 {
112  return false;
113 }
AAMP_LogLevel
AAMP_LogLevel
Log level's of AAMP.
Definition: AampLogManager.h:97
AampLogManager.h
Log managed for Aamp.
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
logprintf
void logprintf(const char *format,...)
Print logs to console / log fil.
Definition: aamplogging.cpp:432
DumpBlob
void DumpBlob(const unsigned char *ptr, size_t len)
Compactly log blobs of binary data.
Definition: aamplogging.cpp:533
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
MediaType
MediaType
Media types.
Definition: AampMediaType.h:37
AAMPNetworkErrorType
AAMPNetworkErrorType
Log level network error enum.
Definition: AampLogManager.h:109
AampLogManager::isLogworthyErrorCode
bool isLogworthyErrorCode(int errorCode)
Check curl error before log on console.
Definition: aamplogging.cpp:417
logprintf_new
void logprintf_new(int playerId, const char *levelstr, const char *file, int line, const char *format,...)
Print logs to console / log file.
Definition: aamplogging.cpp:482
AampLogManager::isLogLevelAllowed
bool isLogLevelAllowed(AAMP_LogLevel chkLevel)
To check the given log level is allowed to print mechanism.
Definition: aamplogging.cpp:50
priv_aamp.h
Private functions and types used internally by AAMP.
MAX_DEBUG_LOG_BUFF_SIZE
#define MAX_DEBUG_LOG_BUFF_SIZE
Max debug log buffer size.
Definition: priv_aamp.h:114
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
AampLogManager::setLogLevel
void setLogLevel(AAMP_LogLevel newLevel)
Set the log level for print mechanism.
Definition: aamplogging.cpp:58