summaryrefslogtreecommitdiff
path: root/absl/log/log.h
diff options
context:
space:
mode:
authorGravatar Mike Kruskal <mkruskal@google.com>2022-12-06 12:38:52 -0800
committerGravatar Copybara-Service <copybara-worker@google.com>2022-12-06 12:39:58 -0800
commita99a183cabbc445aa36d2270795e0d6ff1f25dbf (patch)
tree70377d9f07f94a4518cc0803e0d72b096a9e9c43 /absl/log/log.h
parent6dab0bd99c5856e747fe35e928395ae80ca5e5f1 (diff)
Move implementations of absl logging to an internal file.
This will allow us to create ABSL_-prefixed variants with shared implementation. PiperOrigin-RevId: 493383908 Change-Id: I3529021df7afa642fadaf43eb9fd8249e9202758
Diffstat (limited to 'absl/log/log.h')
-rw-r--r--absl/log/log.h223
1 files changed, 48 insertions, 175 deletions
diff --git a/absl/log/log.h b/absl/log/log.h
index 4cd52041..e060a0b6 100644
--- a/absl/log/log.h
+++ b/absl/log/log.h
@@ -187,9 +187,7 @@
#ifndef ABSL_LOG_LOG_H_
#define ABSL_LOG_LOG_H_
-#include "absl/log/internal/conditions.h"
-#include "absl/log/internal/log_message.h"
-#include "absl/log/internal/strip.h"
+#include "absl/log/internal/log_impl.h"
// LOG()
//
@@ -198,56 +196,29 @@
// Example:
//
// LOG(INFO) << "Found " << num_cookies << " cookies";
-#define LOG(severity) \
- ABSL_LOG_INTERNAL_CONDITION_##severity(STATELESS, true) \
- ABSL_LOGGING_INTERNAL_LOG_##severity.InternalStream()
+#define LOG(severity) ABSL_LOG_IMPL(_##severity)
// PLOG()
//
// `PLOG` behaves like `LOG` except that a description of the current state of
// `errno` is appended to the streamed message.
-#define PLOG(severity) \
- ABSL_LOG_INTERNAL_CONDITION_##severity(STATELESS, true) \
- ABSL_LOGGING_INTERNAL_LOG_##severity.InternalStream() \
- .WithPerror()
+#define PLOG(severity) ABSL_PLOG_IMPL(_##severity)
// DLOG()
//
// `DLOG` behaves like `LOG` in debug mode (i.e. `#ifndef NDEBUG`). Otherwise
// it compiles away and does nothing. Note that `DLOG(FATAL)` does not
// terminate the program if `NDEBUG` is defined.
-#ifndef NDEBUG
-#define DLOG(severity) \
- ABSL_LOG_INTERNAL_CONDITION_##severity(STATELESS, true) \
- ABSL_LOGGING_INTERNAL_LOG_##severity.InternalStream()
-#else
-#define DLOG(severity) \
- ABSL_LOG_INTERNAL_CONDITION_##severity(STATELESS, false) \
- ABSL_LOGGING_INTERNAL_LOG_##severity.InternalStream()
-#endif
+#define DLOG(severity) ABSL_DLOG_IMPL(_##severity)
// `LOG_IF` and friends add a second argument which specifies a condition. If
// the condition is false, nothing is logged.
// Example:
//
// LOG_IF(INFO, num_cookies > 10) << "Got lots of cookies";
-#define LOG_IF(severity, condition) \
- ABSL_LOG_INTERNAL_CONDITION_##severity(STATELESS, condition) \
- ABSL_LOGGING_INTERNAL_LOG_##severity.InternalStream()
-#define PLOG_IF(severity, condition) \
- ABSL_LOG_INTERNAL_CONDITION_##severity(STATELESS, condition) \
- ABSL_LOGGING_INTERNAL_LOG_##severity.InternalStream() \
- .WithPerror()
-
-#ifndef NDEBUG
-#define DLOG_IF(severity, condition) \
- ABSL_LOG_INTERNAL_CONDITION_##severity(STATELESS, condition) \
- ABSL_LOGGING_INTERNAL_LOG_##severity.InternalStream()
-#else
-#define DLOG_IF(severity, condition) \
- ABSL_LOG_INTERNAL_CONDITION_##severity(STATELESS, false && (condition)) \
- ABSL_LOGGING_INTERNAL_LOG_##severity.InternalStream()
-#endif
+#define LOG_IF(severity, condition) ABSL_LOG_IF_IMPL(_##severity, condition)
+#define PLOG_IF(severity, condition) ABSL_PLOG_IF_IMPL(_##severity, condition)
+#define DLOG_IF(severity, condition) ABSL_DLOG_IF_IMPL(_##severity, condition)
// LOG_EVERY_N
//
@@ -260,27 +231,21 @@
//
// LOG_EVERY_N(WARNING, 1000) << "Got a packet with a bad CRC (" << COUNTER
// << " total)";
-#define LOG_EVERY_N(severity, n) \
- ABSL_LOG_INTERNAL_CONDITION_##severity(STATEFUL, true)(EveryN, n) \
- ABSL_LOGGING_INTERNAL_LOG_##severity.InternalStream()
+#define LOG_EVERY_N(severity, n) ABSL_LOG_EVERY_N_IMPL(_##severity, n)
// LOG_FIRST_N
//
// `LOG_FIRST_N` behaves like `LOG_EVERY_N` except that the specified message is
// logged when the counter's value is less than `n`. `LOG_FIRST_N` is
// thread-safe.
-#define LOG_FIRST_N(severity, n) \
- ABSL_LOG_INTERNAL_CONDITION_##severity(STATEFUL, true)(FirstN, n) \
- ABSL_LOGGING_INTERNAL_LOG_##severity.InternalStream()
+#define LOG_FIRST_N(severity, n) ABSL_LOG_FIRST_N_IMPL(_##severity, n)
// LOG_EVERY_POW_2
//
// `LOG_EVERY_POW_2` behaves like `LOG_EVERY_N` except that the specified
// message is logged when the counter's value is a power of 2.
// `LOG_EVERY_POW_2` is thread-safe.
-#define LOG_EVERY_POW_2(severity) \
- ABSL_LOG_INTERNAL_CONDITION_##severity(STATEFUL, true)(EveryPow2) \
- ABSL_LOGGING_INTERNAL_LOG_##severity.InternalStream()
+#define LOG_EVERY_POW_2(severity) ABSL_LOG_EVERY_POW_2_IMPL(_##severity)
// LOG_EVERY_N_SEC
//
@@ -291,64 +256,20 @@
// Example:
//
// LOG_EVERY_N_SEC(INFO, 2.5) << "Got " << COUNTER << " cookies so far";
-#define LOG_EVERY_N_SEC(severity, n_seconds) \
- ABSL_LOG_INTERNAL_CONDITION_##severity(STATEFUL, true)(EveryNSec, n_seconds) \
- ABSL_LOGGING_INTERNAL_LOG_##severity.InternalStream()
-
-#define PLOG_EVERY_N(severity, n) \
- ABSL_LOG_INTERNAL_CONDITION_##severity(STATEFUL, true)(EveryN, n) \
- ABSL_LOGGING_INTERNAL_LOG_##severity.InternalStream() \
- .WithPerror()
-
-#define PLOG_FIRST_N(severity, n) \
- ABSL_LOG_INTERNAL_CONDITION_##severity(STATEFUL, true)(FirstN, n) \
- ABSL_LOGGING_INTERNAL_LOG_##severity.InternalStream() \
- .WithPerror()
-
-#define PLOG_EVERY_POW_2(severity) \
- ABSL_LOG_INTERNAL_CONDITION_##severity(STATEFUL, true)(EveryPow2) \
- ABSL_LOGGING_INTERNAL_LOG_##severity.InternalStream() \
- .WithPerror()
-
-#define PLOG_EVERY_N_SEC(severity, n_seconds) \
- ABSL_LOG_INTERNAL_CONDITION_##severity(STATEFUL, true)(EveryNSec, n_seconds) \
- ABSL_LOGGING_INTERNAL_LOG_##severity.InternalStream() \
- .WithPerror()
-
-#ifndef NDEBUG
-#define DLOG_EVERY_N(severity, n) \
- ABSL_LOG_INTERNAL_CONDITION_INFO(STATEFUL, true) \
- (EveryN, n) ABSL_LOGGING_INTERNAL_LOG_##severity.InternalStream()
-
-#define DLOG_FIRST_N(severity, n) \
- ABSL_LOG_INTERNAL_CONDITION_INFO(STATEFUL, true) \
- (FirstN, n) ABSL_LOGGING_INTERNAL_LOG_##severity.InternalStream()
+#define LOG_EVERY_N_SEC(severity, n_seconds) \
+ ABSL_LOG_EVERY_N_SEC_IMPL(_##severity, n_seconds)
-#define DLOG_EVERY_POW_2(severity) \
- ABSL_LOG_INTERNAL_CONDITION_INFO(STATEFUL, true) \
- (EveryPow2) ABSL_LOGGING_INTERNAL_LOG_##severity.InternalStream()
+#define PLOG_EVERY_N(severity, n) ABSL_PLOG_EVERY_N_IMPL(_##severity, n)
+#define PLOG_FIRST_N(severity, n) ABSL_PLOG_FIRST_N_IMPL(_##severity, n)
+#define PLOG_EVERY_POW_2(severity) ABSL_PLOG_EVERY_POW_2_IMPL(_##severity)
+#define PLOG_EVERY_N_SEC(severity, n_seconds) \
+ ABSL_PLOG_EVERY_N_SEC_IMPL(_##severity, n_seconds)
-#define DLOG_EVERY_N_SEC(severity, n_seconds) \
- ABSL_LOG_INTERNAL_CONDITION_INFO(STATEFUL, true) \
- (EveryNSec, n_seconds) ABSL_LOGGING_INTERNAL_LOG_##severity.InternalStream()
-
-#else // def NDEBUG
-#define DLOG_EVERY_N(severity, n) \
- ABSL_LOG_INTERNAL_CONDITION_INFO(STATEFUL, false) \
- (EveryN, n) ABSL_LOGGING_INTERNAL_LOG_##severity.InternalStream()
-
-#define DLOG_FIRST_N(severity, n) \
- ABSL_LOG_INTERNAL_CONDITION_INFO(STATEFUL, false) \
- (FirstN, n) ABSL_LOGGING_INTERNAL_LOG_##severity.InternalStream()
-
-#define DLOG_EVERY_POW_2(severity) \
- ABSL_LOG_INTERNAL_CONDITION_INFO(STATEFUL, false) \
- (EveryPow2) ABSL_LOGGING_INTERNAL_LOG_##severity.InternalStream()
-
-#define DLOG_EVERY_N_SEC(severity, n_seconds) \
- ABSL_LOG_INTERNAL_CONDITION_INFO(STATEFUL, false) \
- (EveryNSec, n_seconds) ABSL_LOGGING_INTERNAL_LOG_##severity.InternalStream()
-#endif // def NDEBUG
+#define DLOG_EVERY_N(severity, n) ABSL_DLOG_EVERY_N_IMPL(_##severity, n)
+#define DLOG_FIRST_N(severity, n) ABSL_DLOG_FIRST_N_IMPL(_##severity, n)
+#define DLOG_EVERY_POW_2(severity) ABSL_DLOG_EVERY_POW_2_IMPL(_##severity)
+#define DLOG_EVERY_N_SEC(severity, n_seconds) \
+ ABSL_DLOG_EVERY_N_SEC_IMPL(_##severity, n_seconds)
// `LOG_IF_EVERY_N` and friends behave as the corresponding `LOG_EVERY_N`
// but neither increment a counter nor log a message if condition is false (as
@@ -357,79 +278,31 @@
//
// LOG_IF_EVERY_N(INFO, (size > 1024), 10) << "Got the " << COUNTER
// << "th big cookie";
-#define LOG_IF_EVERY_N(severity, condition, n) \
- ABSL_LOG_INTERNAL_CONDITION_##severity(STATEFUL, condition)(EveryN, n) \
- ABSL_LOGGING_INTERNAL_LOG_##severity.InternalStream()
-
-#define LOG_IF_FIRST_N(severity, condition, n) \
- ABSL_LOG_INTERNAL_CONDITION_##severity(STATEFUL, condition)(FirstN, n) \
- ABSL_LOGGING_INTERNAL_LOG_##severity.InternalStream()
-
-#define LOG_IF_EVERY_POW_2(severity, condition) \
- ABSL_LOG_INTERNAL_CONDITION_##severity(STATEFUL, condition)(EveryPow2) \
- ABSL_LOGGING_INTERNAL_LOG_##severity.InternalStream()
-
-#define LOG_IF_EVERY_N_SEC(severity, condition, n_seconds) \
- ABSL_LOG_INTERNAL_CONDITION_##severity(STATEFUL, condition)(EveryNSec, \
- n_seconds) \
- ABSL_LOGGING_INTERNAL_LOG_##severity.InternalStream()
-
-#define PLOG_IF_EVERY_N(severity, condition, n) \
- ABSL_LOG_INTERNAL_CONDITION_##severity(STATEFUL, condition)(EveryN, n) \
- ABSL_LOGGING_INTERNAL_LOG_##severity.InternalStream() \
- .WithPerror()
-
-#define PLOG_IF_FIRST_N(severity, condition, n) \
- ABSL_LOG_INTERNAL_CONDITION_##severity(STATEFUL, condition)(FirstN, n) \
- ABSL_LOGGING_INTERNAL_LOG_##severity.InternalStream() \
- .WithPerror()
-
-#define PLOG_IF_EVERY_POW_2(severity, condition) \
- ABSL_LOG_INTERNAL_CONDITION_##severity(STATEFUL, condition)(EveryPow2) \
- ABSL_LOGGING_INTERNAL_LOG_##severity.InternalStream() \
- .WithPerror()
-
-#define PLOG_IF_EVERY_N_SEC(severity, condition, n_seconds) \
- ABSL_LOG_INTERNAL_CONDITION_##severity(STATEFUL, condition)(EveryNSec, \
- n_seconds) \
- ABSL_LOGGING_INTERNAL_LOG_##severity.InternalStream() \
- .WithPerror()
-
-#ifndef NDEBUG
-#define DLOG_IF_EVERY_N(severity, condition, n) \
- ABSL_LOG_INTERNAL_CONDITION_##severity(STATEFUL, condition)(EveryN, n) \
- ABSL_LOGGING_INTERNAL_LOG_##severity.InternalStream()
-
-#define DLOG_IF_FIRST_N(severity, condition, n) \
- ABSL_LOG_INTERNAL_CONDITION_##severity(STATEFUL, condition)(FirstN, n) \
- ABSL_LOGGING_INTERNAL_LOG_##severity.InternalStream()
-
-#define DLOG_IF_EVERY_POW_2(severity, condition) \
- ABSL_LOG_INTERNAL_CONDITION_##severity(STATEFUL, condition)(EveryPow2) \
- ABSL_LOGGING_INTERNAL_LOG_##severity.InternalStream()
-
-#define DLOG_IF_EVERY_N_SEC(severity, condition, n_seconds) \
- ABSL_LOG_INTERNAL_CONDITION_##severity(STATEFUL, condition)(EveryNSec, \
- n_seconds) \
- ABSL_LOGGING_INTERNAL_LOG_##severity.InternalStream()
-
-#else // def NDEBUG
-#define DLOG_IF_EVERY_N(severity, condition, n) \
- ABSL_LOG_INTERNAL_CONDITION_##severity(STATEFUL, false && (condition))( \
- EveryN, n) ABSL_LOGGING_INTERNAL_LOG_##severity.InternalStream()
-
-#define DLOG_IF_FIRST_N(severity, condition, n) \
- ABSL_LOG_INTERNAL_CONDITION_##severity(STATEFUL, false && (condition))( \
- FirstN, n) ABSL_LOGGING_INTERNAL_LOG_##severity.InternalStream()
-
-#define DLOG_IF_EVERY_POW_2(severity, condition) \
- ABSL_LOG_INTERNAL_CONDITION_##severity(STATEFUL, false && (condition))( \
- EveryPow2) ABSL_LOGGING_INTERNAL_LOG_##severity.InternalStream()
-
-#define DLOG_IF_EVERY_N_SEC(severity, condition, n_seconds) \
- ABSL_LOG_INTERNAL_CONDITION_##severity(STATEFUL, false && (condition))( \
- EveryNSec, n_seconds) \
- ABSL_LOGGING_INTERNAL_LOG_##severity.InternalStream()
-#endif // def NDEBUG
+#define LOG_IF_EVERY_N(severity, condition, n) \
+ ABSL_LOG_IF_EVERY_N_IMPL(_##severity, condition, n)
+#define LOG_IF_FIRST_N(severity, condition, n) \
+ ABSL_LOG_IF_FIRST_N_IMPL(_##severity, condition, n)
+#define LOG_IF_EVERY_POW_2(severity, condition) \
+ ABSL_LOG_IF_EVERY_POW_2_IMPL(_##severity, condition)
+#define LOG_IF_EVERY_N_SEC(severity, condition, n_seconds) \
+ ABSL_LOG_IF_EVERY_N_SEC_IMPL(_##severity, condition, n_seconds)
+
+#define PLOG_IF_EVERY_N(severity, condition, n) \
+ ABSL_PLOG_IF_EVERY_N_IMPL(_##severity, condition, n)
+#define PLOG_IF_FIRST_N(severity, condition, n) \
+ ABSL_PLOG_IF_FIRST_N_IMPL(_##severity, condition, n)
+#define PLOG_IF_EVERY_POW_2(severity, condition) \
+ ABSL_PLOG_IF_EVERY_POW_2_IMPL(_##severity, condition)
+#define PLOG_IF_EVERY_N_SEC(severity, condition, n_seconds) \
+ ABSL_PLOG_IF_EVERY_N_SEC_IMPL(_##severity, condition, n_seconds)
+
+#define DLOG_IF_EVERY_N(severity, condition, n) \
+ ABSL_DLOG_IF_EVERY_N_IMPL(_##severity, condition, n)
+#define DLOG_IF_FIRST_N(severity, condition, n) \
+ ABSL_DLOG_IF_FIRST_N_IMPL(_##severity, condition, n)
+#define DLOG_IF_EVERY_POW_2(severity, condition) \
+ ABSL_DLOG_IF_EVERY_POW_2_IMPL(_##severity, condition)
+#define DLOG_IF_EVERY_N_SEC(severity, condition, n_seconds) \
+ ABSL_DLOG_IF_EVERY_N_SEC_IMPL(_##severity, condition, n_seconds)
#endif // ABSL_LOG_LOG_H_