Merge changes Id67203bb,I0c1dd57f

* changes:
  liblog: move LOG_ID_DEFAULT into the log_id enum
  liblog: use int32_t and uint32_t for new NDK APIs
This commit is contained in:
Tom Cherry 2020-03-13 16:10:35 +00:00 committed by Gerrit Code Review
commit c74afeaa8b
5 changed files with 28 additions and 27 deletions

View file

@ -36,8 +36,8 @@ struct LibLogFunctions {
void (*__android_log_set_aborter)(__android_aborter_function aborter);
void (*__android_log_call_aborter)(const char* abort_message);
void (*__android_log_default_aborter)(const char* abort_message);
int (*__android_log_set_minimum_priority)(int priority);
int (*__android_log_get_minimum_priority)();
int32_t (*__android_log_set_minimum_priority)(int32_t priority);
int32_t (*__android_log_get_minimum_priority)();
void (*__android_log_set_default_tag)(const char* tag);
};

View file

@ -118,7 +118,7 @@ static int OpenKmsg() {
}
#endif
static LogId log_id_tToLogId(int buffer_id) {
static LogId log_id_tToLogId(int32_t buffer_id) {
switch (buffer_id) {
case LOG_ID_MAIN:
return MAIN;
@ -134,7 +134,7 @@ static LogId log_id_tToLogId(int buffer_id) {
}
}
static int LogIdTolog_id_t(LogId log_id) {
static int32_t LogIdTolog_id_t(LogId log_id) {
switch (log_id) {
case MAIN:
return LOG_ID_MAIN;
@ -171,7 +171,7 @@ static LogSeverity PriorityToLogSeverity(int priority) {
}
}
static android_LogPriority LogSeverityToPriority(LogSeverity severity) {
static int32_t LogSeverityToPriority(LogSeverity severity) {
switch (severity) {
case VERBOSE:
return ANDROID_LOG_VERBOSE;
@ -333,12 +333,12 @@ LogdLogger::LogdLogger(LogId default_log_id) : default_log_id_(default_log_id) {
void LogdLogger::operator()(LogId id, LogSeverity severity, const char* tag,
const char* file, unsigned int line,
const char* message) {
android_LogPriority priority = LogSeverityToPriority(severity);
int32_t priority = LogSeverityToPriority(severity);
if (id == DEFAULT) {
id = default_log_id_;
}
int lg_id = LogIdTolog_id_t(id);
int32_t lg_id = LogIdTolog_id_t(id);
char log_message_with_file[4068]; // LOGGER_ENTRY_MAX_PAYLOAD, not available in the NDK.
if (priority == ANDROID_LOG_FATAL && file != nullptr) {
@ -574,7 +574,7 @@ std::ostream& LogMessage::stream() {
void LogMessage::LogLine(const char* file, unsigned int line, LogSeverity severity, const char* tag,
const char* message) {
static auto& liblog_functions = GetLibLogFunctions();
auto priority = LogSeverityToPriority(severity);
int32_t priority = LogSeverityToPriority(severity);
if (liblog_functions) {
__android_logger_data logger_data = {
sizeof(__android_logger_data), LOG_ID_DEFAULT, priority, tag, file, line};
@ -608,7 +608,7 @@ bool ShouldLog(LogSeverity severity, const char* tag) {
// we need to fall back to using gMinimumLogSeverity, since __android_log_is_loggable() will not
// take into consideration the value from SetMinimumLogSeverity().
if (liblog_functions) {
int priority = LogSeverityToPriority(severity);
int32_t priority = LogSeverityToPriority(severity);
return __android_log_is_loggable(priority, tag, ANDROID_LOG_INFO);
} else {
return severity >= gMinimumLogSeverity;
@ -618,7 +618,7 @@ bool ShouldLog(LogSeverity severity, const char* tag) {
LogSeverity SetMinimumLogSeverity(LogSeverity new_severity) {
static auto& liblog_functions = GetLibLogFunctions();
if (liblog_functions) {
auto priority = LogSeverityToPriority(new_severity);
int32_t priority = LogSeverityToPriority(new_severity);
return PriorityToLogSeverity(liblog_functions->__android_log_set_minimum_priority(priority));
} else {
LogSeverity old_severity = gMinimumLogSeverity;

View file

@ -56,6 +56,7 @@
#include <stdarg.h>
#include <stddef.h>
#include <stdint.h>
#include <sys/cdefs.h>
#if !defined(__BIONIC__) && !defined(__INTRODUCED_IN)
@ -154,14 +155,11 @@ typedef enum log_id {
/** The kernel log buffer. */
LOG_ID_KERNEL = 7,
LOG_ID_MAX
} log_id_t;
LOG_ID_MAX,
/**
* Let the logging function choose the best log target.
* This is not part of the enum since adding either -1 or 0xFFFFFFFF forces the enum to be signed or
* unsigned, which breaks unfortunately common arithmetic against LOG_ID_MIN and LOG_ID_MAX. */
#define LOG_ID_DEFAULT (-1)
/** Let the logging function choose the best log target. */
LOG_ID_DEFAULT = 0x7FFFFFFF
} log_id_t;
/**
* Writes the constant string `text` to the log buffer `id`,
@ -188,11 +186,11 @@ int __android_log_buf_print(int bufID, int prio, const char* tag, const char* fm
*/
struct __android_logger_data {
size_t struct_size; /* Must be set to sizeof(__android_logger_data) and is used for versioning. */
int buffer_id; /* log_id_t or -1 to represent 'default'. */
int priority; /* android_LogPriority values. */
int32_t buffer_id; /* log_id_t or -1 to represent 'default'. */
int32_t priority; /* android_LogPriority values. */
const char* tag;
const char* file; /* Optional file name, may be set to nullptr. */
unsigned int line; /* Optional line number, ignore if file is nullptr. */
uint32_t line; /* Optional line number, ignore if file is nullptr. */
};
/**
@ -276,13 +274,13 @@ int __android_log_is_loggable_len(int prio, const char* tag, size_t len, int def
*
* This returns the previous set minimum priority, or ANDROID_LOG_DEFAULT if none was set.
*/
int __android_log_set_minimum_priority(int priority) __INTRODUCED_IN(30);
int32_t __android_log_set_minimum_priority(int32_t priority) __INTRODUCED_IN(30);
/**
* Gets the minimum priority that will be logged for this process. If none has been set by a
* previous __android_log_set_minimum_priority() call, this returns ANDROID_LOG_DEFAULT.
*/
int __android_log_get_minimum_priority(void) __INTRODUCED_IN(30);
int32_t __android_log_get_minimum_priority(void) __INTRODUCED_IN(30);
/**
* Sets the default tag if no tag is provided when writing a log message. Defaults to

View file

@ -41,7 +41,10 @@ const char* android_log_id_to_name(log_id_t log_id) {
}
static_assert(std::is_same<std::underlying_type<log_id_t>::type, uint32_t>::value,
"log_id_t must be an unsigned int");
"log_id_t must be an uint32_t");
static_assert(std::is_same<std::underlying_type<android_LogPriority>::type, uint32_t>::value,
"log_id_t must be an uint32_t");
log_id_t android_name_to_log_id(const char* logName) {
const char* b;

View file

@ -149,12 +149,12 @@ void __android_log_set_default_tag(const char* tag) {
GetDefaultTag().assign(tag, 0, LOGGER_ENTRY_MAX_PAYLOAD);
}
static std::atomic_int minimum_log_priority = ANDROID_LOG_DEFAULT;
int __android_log_set_minimum_priority(int priority) {
static std::atomic_int32_t minimum_log_priority = ANDROID_LOG_DEFAULT;
int32_t __android_log_set_minimum_priority(int32_t priority) {
return minimum_log_priority.exchange(priority, std::memory_order_relaxed);
}
int __android_log_get_minimum_priority() {
int32_t __android_log_get_minimum_priority() {
return minimum_log_priority;
}
@ -267,7 +267,7 @@ void __android_log_stderr_logger(const struct __android_logger_data* logger_data
static const char log_characters[] = "XXVDIWEF";
static_assert(arraysize(log_characters) - 1 == ANDROID_LOG_SILENT,
"Mismatch in size of log_characters and values in android_LogPriority");
int priority =
int32_t priority =
logger_data->priority > ANDROID_LOG_SILENT ? ANDROID_LOG_FATAL : logger_data->priority;
char priority_char = log_characters[priority];
uint64_t tid = GetThreadId();