summaryrefslogtreecommitdiff
path: root/absl/log/internal
diff options
context:
space:
mode:
authorGravatar Derek Mauro <dmauro@google.com>2023-12-05 07:07:07 -0800
committerGravatar Copybara-Service <copybara-worker@google.com>2023-12-05 07:07:49 -0800
commit7b6c17e378224844d8663a410da2da5353b205b9 (patch)
tree2f2b43000c977e65ce226cd04f13fdd389a7a0b6 /absl/log/internal
parenta39d71a80fbdf0ee2f00222943c1ca08361cec20 (diff)
Add VLOG and friends
These are methods for configurable verbose logging PiperOrigin-RevId: 588059727 Change-Id: Ib3703edd2493050a5da8b30e88b21adc643b1f7f
Diffstat (limited to 'absl/log/internal')
-rw-r--r--absl/log/internal/BUILD.bazel1
-rw-r--r--absl/log/internal/flags.h6
-rw-r--r--absl/log/internal/log_impl.h66
3 files changed, 73 insertions, 0 deletions
diff --git a/absl/log/internal/BUILD.bazel b/absl/log/internal/BUILD.bazel
index 2030a3d7..90643a5e 100644
--- a/absl/log/internal/BUILD.bazel
+++ b/absl/log/internal/BUILD.bazel
@@ -153,6 +153,7 @@ cc_library(
":conditions",
":log_message",
":strip",
+ "//absl/log:vlog_is_on",
],
)
diff --git a/absl/log/internal/flags.h b/absl/log/internal/flags.h
index b91b8644..c4539785 100644
--- a/absl/log/internal/flags.h
+++ b/absl/log/internal/flags.h
@@ -50,4 +50,10 @@ ABSL_DECLARE_FLAG(std::string, log_backtrace_at);
// each message logged. Defaults to true.
ABSL_DECLARE_FLAG(bool, log_prefix);
+// Global log verbosity level. Default is 0.
+ABSL_DECLARE_FLAG(int, v);
+
+// Per-module log verbosity level. By default is empty and is unused.
+ABSL_DECLARE_FLAG(std::string, vmodule);
+
#endif // ABSL_LOG_INTERNAL_FLAGS_H_
diff --git a/absl/log/internal/log_impl.h b/absl/log/internal/log_impl.h
index 9326780d..ba90eda8 100644
--- a/absl/log/internal/log_impl.h
+++ b/absl/log/internal/log_impl.h
@@ -18,6 +18,7 @@
#include "absl/log/internal/conditions.h"
#include "absl/log/internal/log_message.h"
#include "absl/log/internal/strip.h"
+#include "absl/log/vlog_is_on.h"
// ABSL_LOG()
#define ABSL_LOG_INTERNAL_LOG_IMPL(severity) \
@@ -41,6 +42,35 @@
ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
#endif
+// The `switch` ensures that this expansion is the begnning of a statement (as
+// opposed to an expression). The use of both `case 0` and `default` is to
+// suppress a compiler warning.
+#define ABSL_LOG_INTERNAL_VLOG_IMPL(verbose_level) \
+ switch (const int absl_logging_internal_verbose_level = (verbose_level)) \
+ case 0: \
+ default: \
+ ABSL_LOG_INTERNAL_LOG_IF_IMPL( \
+ _INFO, VLOG_IS_ON(absl_logging_internal_verbose_level)) \
+ .WithVerbosity(absl_logging_internal_verbose_level)
+
+#ifndef NDEBUG
+#define ABSL_LOG_INTERNAL_DVLOG_IMPL(verbose_level) \
+ switch (const int absl_logging_internal_verbose_level = (verbose_level)) \
+ case 0: \
+ default: \
+ ABSL_LOG_INTERNAL_LOG_IF_IMPL( \
+ _INFO, VLOG_IS_ON(absl_logging_internal_verbose_level)) \
+ .WithVerbosity(absl_logging_internal_verbose_level)
+#else
+#define ABSL_LOG_INTERNAL_DVLOG_IMPL(verbose_level) \
+ switch (const int absl_logging_internal_verbose_level = (verbose_level)) \
+ case 0: \
+ default: \
+ ABSL_LOG_INTERNAL_LOG_IF_IMPL( \
+ _INFO, false && VLOG_IS_ON(absl_logging_internal_verbose_level)) \
+ .WithVerbosity(absl_logging_internal_verbose_level)
+#endif
+
#define ABSL_LOG_INTERNAL_LOG_IF_IMPL(severity, condition) \
ABSL_LOG_INTERNAL_CONDITION##severity(STATELESS, condition) \
ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
@@ -134,6 +164,42 @@
(EveryNSec, n_seconds) ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
#endif // def NDEBUG
+#define ABSL_LOG_INTERNAL_VLOG_EVERY_N_IMPL(verbose_level, n) \
+ switch (const int absl_logging_internal_verbose_level = (verbose_level)) \
+ case 0: \
+ default: \
+ ABSL_LOG_INTERNAL_CONDITION_INFO( \
+ STATEFUL, VLOG_IS_ON(absl_logging_internal_verbose_level)) \
+ (EveryN, n) ABSL_LOGGING_INTERNAL_LOG_INFO.InternalStream().WithVerbosity( \
+ absl_logging_internal_verbose_level)
+
+#define ABSL_LOG_INTERNAL_VLOG_FIRST_N_IMPL(verbose_level, n) \
+ switch (const int absl_logging_internal_verbose_level = (verbose_level)) \
+ case 0: \
+ default: \
+ ABSL_LOG_INTERNAL_CONDITION_INFO( \
+ STATEFUL, VLOG_IS_ON(absl_logging_internal_verbose_level)) \
+ (FirstN, n) ABSL_LOGGING_INTERNAL_LOG_INFO.InternalStream().WithVerbosity( \
+ absl_logging_internal_verbose_level)
+
+#define ABSL_LOG_INTERNAL_VLOG_EVERY_POW_2_IMPL(verbose_level) \
+ switch (const int absl_logging_internal_verbose_level = (verbose_level)) \
+ case 0: \
+ default: \
+ ABSL_LOG_INTERNAL_CONDITION_INFO( \
+ STATEFUL, VLOG_IS_ON(absl_logging_internal_verbose_level)) \
+ (EveryPow2) ABSL_LOGGING_INTERNAL_LOG_INFO.InternalStream().WithVerbosity( \
+ absl_logging_internal_verbose_level)
+
+#define ABSL_LOG_INTERNAL_VLOG_EVERY_N_SEC_IMPL(verbose_level, n_seconds) \
+ switch (const int absl_logging_internal_verbose_level = (verbose_level)) \
+ case 0: \
+ default: \
+ ABSL_LOG_INTERNAL_CONDITION_INFO( \
+ STATEFUL, VLOG_IS_ON(absl_logging_internal_verbose_level)) \
+ (EveryNSec, n_seconds) ABSL_LOGGING_INTERNAL_LOG_INFO.InternalStream() \
+ .WithVerbosity(absl_logging_internal_verbose_level)
+
#define ABSL_LOG_INTERNAL_LOG_IF_EVERY_N_IMPL(severity, condition, n) \
ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, condition)(EveryN, n) \
ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()