fix: unify additional debug output (#1050)
This commit is contained in:
parent
7af231e6bf
commit
c469cc23a1
@ -88,10 +88,6 @@
|
|||||||
# include <syslog.h>
|
# include <syslog.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __ANDROID__
|
|
||||||
# include <android/log.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef HAVE_SYS_TYPES_H
|
#ifdef HAVE_SYS_TYPES_H
|
||||||
# include <sys/types.h>
|
# include <sys/types.h>
|
||||||
#endif
|
#endif
|
||||||
@ -787,24 +783,9 @@ inline void LogDestination::MaybeLogToStderr(LogSeverity severity,
|
|||||||
size_t prefix_len) {
|
size_t prefix_len) {
|
||||||
if ((severity >= FLAGS_stderrthreshold) || FLAGS_alsologtostderr) {
|
if ((severity >= FLAGS_stderrthreshold) || FLAGS_alsologtostderr) {
|
||||||
ColoredWriteToStderr(severity, message, message_len);
|
ColoredWriteToStderr(severity, message, message_len);
|
||||||
#ifdef GLOG_OS_WINDOWS
|
AlsoErrorWrite(severity,
|
||||||
(void)prefix_len;
|
glog_internal_namespace_::ProgramInvocationShortName(),
|
||||||
// On Windows, also output to the debugger
|
message + prefix_len);
|
||||||
::OutputDebugStringA(message);
|
|
||||||
#elif defined(__ANDROID__)
|
|
||||||
// On Android, also output to logcat
|
|
||||||
const int android_log_levels[NUM_SEVERITIES] = {
|
|
||||||
ANDROID_LOG_INFO,
|
|
||||||
ANDROID_LOG_WARN,
|
|
||||||
ANDROID_LOG_ERROR,
|
|
||||||
ANDROID_LOG_FATAL,
|
|
||||||
};
|
|
||||||
__android_log_write(android_log_levels[severity],
|
|
||||||
glog_internal_namespace_::ProgramInvocationShortName(),
|
|
||||||
message + prefix_len);
|
|
||||||
#else
|
|
||||||
(void)prefix_len;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1850,12 +1831,9 @@ void LogMessage::SendToLog() EXCLUSIVE_LOCKS_REQUIRED(log_mutex) {
|
|||||||
if (write(STDERR_FILENO, message, strlen(message)) < 0) {
|
if (write(STDERR_FILENO, message, strlen(message)) < 0) {
|
||||||
// Ignore errors.
|
// Ignore errors.
|
||||||
}
|
}
|
||||||
#if defined(__ANDROID__)
|
AlsoErrorWrite(GLOG_FATAL,
|
||||||
// ANDROID_LOG_FATAL as this message is of FATAL severity.
|
glog_internal_namespace_::ProgramInvocationShortName(),
|
||||||
__android_log_write(ANDROID_LOG_FATAL,
|
message);
|
||||||
glog_internal_namespace_::ProgramInvocationShortName(),
|
|
||||||
message);
|
|
||||||
#endif
|
|
||||||
Fail();
|
Fail();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -38,11 +38,13 @@
|
|||||||
#include <csignal>
|
#include <csignal>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <ctime>
|
|
||||||
|
|
||||||
#include "base/googleinit.h"
|
#include "base/googleinit.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
#ifdef __ANDROID__
|
||||||
|
# include <android/log.h>
|
||||||
|
#endif
|
||||||
#ifdef HAVE_SYS_TIME_H
|
#ifdef HAVE_SYS_TIME_H
|
||||||
# include <sys/time.h>
|
# include <sys/time.h>
|
||||||
#endif
|
#endif
|
||||||
@ -60,9 +62,6 @@
|
|||||||
#ifdef HAVE_PWD_H
|
#ifdef HAVE_PWD_H
|
||||||
# include <pwd.h>
|
# include <pwd.h>
|
||||||
#endif
|
#endif
|
||||||
#ifdef __ANDROID__
|
|
||||||
# include <android/log.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(HAVE___PROGNAME)
|
#if defined(HAVE___PROGNAME)
|
||||||
extern char* __progname;
|
extern char* __progname;
|
||||||
@ -82,6 +81,29 @@ inline namespace glog_internal_namespace_ {
|
|||||||
|
|
||||||
constexpr int FileDescriptor::InvalidHandle;
|
constexpr int FileDescriptor::InvalidHandle;
|
||||||
|
|
||||||
|
void AlsoErrorWrite(LogSeverity severity, const char* tag,
|
||||||
|
const char* message) noexcept {
|
||||||
|
#if defined(GLOG_OS_WINDOWS)
|
||||||
|
(void)severity;
|
||||||
|
(void)tag;
|
||||||
|
// On Windows, also output to the debugger
|
||||||
|
::OutputDebugStringA(message);
|
||||||
|
#elif defined(__ANDROID__)
|
||||||
|
constexpr int android_log_levels[] = {
|
||||||
|
ANDROID_LOG_INFO,
|
||||||
|
ANDROID_LOG_WARN,
|
||||||
|
ANDROID_LOG_ERROR,
|
||||||
|
ANDROID_LOG_FATAL,
|
||||||
|
};
|
||||||
|
|
||||||
|
__android_log_write(android_log_levels[severity], tag, message);
|
||||||
|
#else
|
||||||
|
(void)severity;
|
||||||
|
(void)tag;
|
||||||
|
(void)message;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace glog_internal_namespace_
|
} // namespace glog_internal_namespace_
|
||||||
|
|
||||||
} // namespace google
|
} // namespace google
|
||||||
@ -106,12 +128,8 @@ static void DebugWriteToStderr(const char* data, void*) {
|
|||||||
if (write(STDERR_FILENO, data, strlen(data)) < 0) {
|
if (write(STDERR_FILENO, data, strlen(data)) < 0) {
|
||||||
// Ignore errors.
|
// Ignore errors.
|
||||||
}
|
}
|
||||||
# if defined(__ANDROID__)
|
AlsoErrorWrite(GLOG_FATAL,
|
||||||
// ANDROID_LOG_FATAL as fatal error occurred and now is dumping call stack.
|
glog_internal_namespace_::ProgramInvocationShortName(), data);
|
||||||
__android_log_write(ANDROID_LOG_FATAL,
|
|
||||||
glog_internal_namespace_::ProgramInvocationShortName(),
|
|
||||||
data);
|
|
||||||
# endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void DebugWriteToString(const char* data, void* arg) {
|
static void DebugWriteToString(const char* data, void* arg) {
|
||||||
|
|||||||
@ -186,6 +186,9 @@ inline namespace glog_internal_namespace_ {
|
|||||||
# define ATTRIBUTE_NOINLINE
|
# define ATTRIBUTE_NOINLINE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
void AlsoErrorWrite(LogSeverity severity, const char* tag,
|
||||||
|
const char* message) noexcept;
|
||||||
|
|
||||||
const char* ProgramInvocationShortName();
|
const char* ProgramInvocationShortName();
|
||||||
|
|
||||||
int32 GetMainThreadPid();
|
int32 GetMainThreadPid();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user