Source release 17.1.0
This commit is contained in:
@@ -1,41 +1,85 @@
|
||||
// Copyright 2018 Google LLC. All Rights Reserved. This file and proprietary
|
||||
// source code may only be used and distributed under the Widevine Master
|
||||
// License Agreement.
|
||||
// source code may only be used and distributed under the Widevine License
|
||||
// Agreement.
|
||||
//
|
||||
// Log - Platform independent interface for a Logging class
|
||||
//
|
||||
#ifndef WVCDM_UTIL_LOG_H_
|
||||
#define WVCDM_UTIL_LOG_H_
|
||||
|
||||
#include <cstdint>
|
||||
#include <deque>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "util_common.h"
|
||||
|
||||
namespace wvcdm {
|
||||
namespace wvutil {
|
||||
|
||||
// Simple logging class. The implementation is platform dependent.
|
||||
|
||||
typedef enum {
|
||||
// This log level should only be used for |g_cutoff|, in order to silence all
|
||||
// logging. It should never be passed to |Log()| as a log level.
|
||||
LOG_SILENT = -1,
|
||||
CDM_LOG_SILENT = -1,
|
||||
|
||||
LOG_ERROR = 0,
|
||||
LOG_WARN = 1,
|
||||
LOG_INFO = 2,
|
||||
LOG_DEBUG = 3,
|
||||
LOG_VERBOSE = 4,
|
||||
CDM_LOG_ERROR = 0,
|
||||
CDM_LOG_WARN = 1,
|
||||
CDM_LOG_INFO = 2,
|
||||
CDM_LOG_DEBUG = 3,
|
||||
CDM_LOG_VERBOSE = 4,
|
||||
} LogPriority;
|
||||
|
||||
extern LogPriority g_cutoff;
|
||||
|
||||
struct LogMessage {
|
||||
uint32_t uid_;
|
||||
int64_t time_ms_;
|
||||
LogPriority priority_;
|
||||
std::string message_;
|
||||
};
|
||||
|
||||
class LogBuffer {
|
||||
public:
|
||||
static const int MAX_CAPACITY = 100;
|
||||
void addLog(const LogMessage& log);
|
||||
std::vector<LogMessage> getLogs();
|
||||
|
||||
private:
|
||||
std::deque<LogMessage> buffer_;
|
||||
std::mutex mutex_;
|
||||
};
|
||||
|
||||
extern LogBuffer g_logbuf;
|
||||
|
||||
static const uint32_t UNKNOWN_UID = std::numeric_limits<uint32_t>::max();
|
||||
|
||||
#ifdef __ANDROID__
|
||||
void SetLoggingUid(const uint32_t);
|
||||
void ClearLoggingUid();
|
||||
uint32_t GetLoggingUid();
|
||||
uint32_t GetIpcCallingUid();
|
||||
#else
|
||||
static inline void SetLoggingUid(const uint32_t) {}
|
||||
static inline void ClearLoggingUid() {}
|
||||
static inline uint32_t GetLoggingUid() { return UNKNOWN_UID; }
|
||||
static inline uint32_t GetIpcCallingUid() { return UNKNOWN_UID; }
|
||||
#endif
|
||||
|
||||
struct LoggingUidSetter {
|
||||
LoggingUidSetter() {}
|
||||
LoggingUidSetter(uint32_t uid) { SetLoggingUid(uid); }
|
||||
virtual ~LoggingUidSetter() { ClearLoggingUid(); }
|
||||
};
|
||||
|
||||
// Enable/disable verbose logging (LOGV).
|
||||
// This function is supplied for cases where the system layer does not
|
||||
// initialize logging. This is also needed to initialize logging in
|
||||
// unit tests.
|
||||
CORE_UTIL_EXPORT void InitLogging();
|
||||
|
||||
// Only enable format specifier warnings on LP64 systems. There is
|
||||
// no easy portable method to handle format specifiers for int64_t.
|
||||
#if (defined(__gnuc__) || defined(__clang__)) && defined(__LP64__)
|
||||
#ifdef __GNUC__
|
||||
[[gnu::format(printf, 5, 6)]] CORE_UTIL_EXPORT void Log(const char* file,
|
||||
const char* function,
|
||||
int line,
|
||||
@@ -47,18 +91,26 @@ CORE_UTIL_EXPORT void Log(const char* file, const char* function, int line,
|
||||
#endif
|
||||
|
||||
// Log APIs
|
||||
#ifndef LOGE
|
||||
# define LOGE(...) \
|
||||
Log(__FILE__, __func__, __LINE__, wvcdm::LOG_ERROR, __VA_ARGS__)
|
||||
# define LOGW(...) \
|
||||
Log(__FILE__, __func__, __LINE__, wvcdm::LOG_WARN, __VA_ARGS__)
|
||||
# define LOGI(...) \
|
||||
Log(__FILE__, __func__, __LINE__, wvcdm::LOG_INFO, __VA_ARGS__)
|
||||
# define LOGD(...) \
|
||||
Log(__FILE__, __func__, __LINE__, wvcdm::LOG_DEBUG, __VA_ARGS__)
|
||||
# define LOGV(...) \
|
||||
Log(__FILE__, __func__, __LINE__, wvcdm::LOG_VERBOSE, __VA_ARGS__)
|
||||
#ifdef CDM_DISABLE_LOGGING
|
||||
# define LOGE(...) (void)0
|
||||
# define LOGW(...) (void)0
|
||||
# define LOGI(...) (void)0
|
||||
# define LOGD(...) (void)0
|
||||
# define LOGV(...) (void)0
|
||||
#else
|
||||
# ifndef LOGE
|
||||
# define LOGE(...) \
|
||||
Log(__FILE__, __func__, __LINE__, wvutil::CDM_LOG_ERROR, __VA_ARGS__)
|
||||
# define LOGW(...) \
|
||||
Log(__FILE__, __func__, __LINE__, wvutil::CDM_LOG_WARN, __VA_ARGS__)
|
||||
# define LOGI(...) \
|
||||
Log(__FILE__, __func__, __LINE__, wvutil::CDM_LOG_INFO, __VA_ARGS__)
|
||||
# define LOGD(...) \
|
||||
Log(__FILE__, __func__, __LINE__, wvutil::CDM_LOG_DEBUG, __VA_ARGS__)
|
||||
# define LOGV(...) \
|
||||
Log(__FILE__, __func__, __LINE__, wvutil::CDM_LOG_VERBOSE, __VA_ARGS__)
|
||||
# endif
|
||||
#endif
|
||||
} // namespace wvcdm
|
||||
} // namespace wvutil
|
||||
|
||||
#endif // WVCDM_UTIL_LOG_H_
|
||||
|
||||
Reference in New Issue
Block a user