38 #if defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || \ 39 defined(__Fuchsia__) || defined(__native_client__) || \ 40 defined(__EMSCRIPTEN__) 44 #define ABSL_HAVE_POSIX_WRITE 1 45 #define ABSL_LOW_LEVEL_WRITE_SUPPORTED 1 47 #undef ABSL_HAVE_POSIX_WRITE 53 #if (defined(__linux__) || defined(__FreeBSD__)) && !defined(__ANDROID__) 54 #include <sys/syscall.h> 55 #define ABSL_HAVE_SYSCALL_WRITE 1 56 #define ABSL_LOW_LEVEL_WRITE_SUPPORTED 1 58 #undef ABSL_HAVE_SYSCALL_WRITE 64 #define ABSL_HAVE_RAW_IO 1 65 #define ABSL_LOW_LEVEL_WRITE_SUPPORTED 1 67 #undef ABSL_HAVE_RAW_IO 79 #ifdef ABSL_LOW_LEVEL_WRITE_SUPPORTED 80 static const char kTruncated[] =
" ... (message truncated)\n";
86 inline static bool VADoRawLog(
char**
buf,
int*
size,
const char*
format,
88 inline static bool VADoRawLog(
char**
buf,
int*
size,
89 const char*
format, va_list ap) {
90 int n = vsnprintf(*buf, *size, format, ap);
92 if (n < 0 || n > *size) {
94 if (static_cast<size_t>(*size) >
sizeof(kTruncated)) {
95 n = *size -
sizeof(kTruncated);
104 #endif // ABSL_LOW_LEVEL_WRITE_SUPPORTED 116 bool DoRawLog(
char** buf,
int* size,
const char* format, ...)
118 bool DoRawLog(
char** buf,
int* size,
const char* format, ...) {
120 va_start(ap, format);
121 int n = vsnprintf(*buf, *size, format, ap);
123 if (n < 0 || n > *size)
return false;
132 const char* format, va_list ap) {
135 int size =
sizeof(buffer);
136 #ifdef ABSL_LOW_LEVEL_WRITE_SUPPORTED 139 bool enabled =
false;
142 #ifdef ABSL_MIN_LOG_LEVEL 143 if (severity < static_cast<absl::LogSeverity>(ABSL_MIN_LOG_LEVEL) &&
150 if (log_prefix_hook_ptr) {
151 enabled = log_prefix_hook_ptr(severity, file, line, &buf, &size);
154 DoRawLog(&buf, &size,
"[%s : %d] RAW: ", file, line);
157 const char*
const prefix_end =
buf;
159 #ifdef ABSL_LOW_LEVEL_WRITE_SUPPORTED 161 bool no_chop = VADoRawLog(&buf, &size, format, ap);
163 DoRawLog(&buf, &size,
"\n");
165 DoRawLog(&buf, &size,
"%s", kTruncated);
170 static_cast<void>(
format);
171 static_cast<void>(ap);
177 abort_hook(file, line, buffer, prefix_end, buffer + kLogBufSize);
185 namespace raw_logging_internal {
187 #if defined(ABSL_HAVE_SYSCALL_WRITE) 188 syscall(SYS_write, STDERR_FILENO, s, len);
189 #elif defined(ABSL_HAVE_POSIX_WRITE) 190 write(STDERR_FILENO, s, len);
191 #elif defined(ABSL_HAVE_RAW_IO) 203 const char* format, ...) {
205 va_start(ap, format);
206 RawLogVA(severity, file, line, format, ap);
215 int line,
const std::string& message) {
216 RawLog(severity, file, line,
"%s", message.c_str());
220 #ifdef ABSL_LOW_LEVEL_WRITE_SUPPORTED 222 #else // !ABSL_LOW_LEVEL_WRITE_SUPPORTED 224 #endif // !ABSL_LOW_LEVEL_WRITE_SUPPORTED 231 internal_log_function.Store(func);
void SafeWriteToStderr(const char *s, size_t len)
void RegisterInternalLogFunction(InternalLogFunction func)
static ABSL_CONST_INIT absl::base_internal::AtomicHook< absl::raw_logging_internal::LogPrefixHook > log_prefix_hook
bool RawLoggingFullySupported()
bool(*)(absl::LogSeverity severity, const char *file, int line, char **buffer, int *buf_size) LogPrefixHook
base_internal::AtomicHook< InternalLogFunction > internal_log_function
static ABSL_CONST_INIT absl::base_internal::AtomicHook< absl::raw_logging_internal::AbortHook > abort_hook
std::string format(const std::string &, const time_point< seconds > &, const femtoseconds &, const time_zone &)
static void DefaultInternalLog(absl::LogSeverity severity, const char *file, int line, const std::string &message)
void RawLog(absl::LogSeverity severity, const char *file, int line, const char *format,...) ABSL_PRINTF_ATTRIBUTE(4
void(*)(absl::LogSeverity severity, const char *file, int line, const std::string &message) InternalLogFunction
static constexpr int kLogBufSize
#define ABSL_PRINTF_ATTRIBUTE(string_index, first_to_check)
void(*)(const char *file, int line, const char *buf_start, const char *prefix_end, const char *buf_end) AbortHook