Files
android/libwvdrmengine/cdm/util/include/log.h
Alex Dale 6bc69d5005 Remove CORE_UTIL_EXPORT
[ Merge of http://go/wvgerrit/155070 ]

These functions are internal utilities and should not be exported from
our library.  IIRC, this was added to aid in Windows tests, but this is
no longer needed.

Bug: 236317198
Test: build_and_run_all_unit_tests.sh
Change-Id: I19beb35a15f0f87dc8f968e1dd5302aed9463e54
2022-08-19 14:38:55 -07:00

112 lines
2.9 KiB
C++

// Copyright 2018 Google LLC. All Rights Reserved. This file and proprietary
// 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 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.
CDM_LOG_SILENT = -1,
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.
void InitLogging();
#ifdef __GNUC__
[[gnu::format(printf, 5, 6)]]
#endif
void Log(const char* file, const char* function, int line,
LogPriority level, const char* fmt, ...);
// Log APIs
#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 wvutil
#endif // WVCDM_UTIL_LOG_H_