summaryrefslogtreecommitdiff
path: root/absl
diff options
context:
space:
mode:
Diffstat (limited to 'absl')
-rw-r--r--absl/log/BUILD.bazel18
-rw-r--r--absl/log/CMakeLists.txt21
-rw-r--r--absl/log/absl_vlog_is_on.h115
-rw-r--r--absl/log/internal/BUILD.bazel2
-rw-r--r--absl/log/internal/log_impl.h26
-rw-r--r--absl/log/vlog_is_on.h49
6 files changed, 162 insertions, 69 deletions
diff --git a/absl/log/BUILD.bazel b/absl/log/BUILD.bazel
index 8d734dbb..af23bb87 100644
--- a/absl/log/BUILD.bazel
+++ b/absl/log/BUILD.bazel
@@ -50,7 +50,6 @@ cc_library(
copts = ABSL_DEFAULT_COPTS,
linkopts = ABSL_DEFAULT_LINKOPTS,
deps = [
- ":vlog_is_on",
"//absl/log/internal:log_impl",
],
)
@@ -239,8 +238,8 @@ cc_library(
)
cc_library(
- name = "vlog_is_on",
- hdrs = ["vlog_is_on.h"],
+ name = "absl_vlog_is_on",
+ hdrs = ["absl_vlog_is_on.h"],
copts = ABSL_DEFAULT_COPTS,
linkopts = ABSL_DEFAULT_LINKOPTS,
visibility = [
@@ -254,6 +253,19 @@ cc_library(
],
)
+cc_library(
+ name = "vlog_is_on",
+ hdrs = ["vlog_is_on.h"],
+ copts = ABSL_DEFAULT_COPTS,
+ linkopts = ABSL_DEFAULT_LINKOPTS,
+ visibility = [
+ "//absl/log:__subpackages__",
+ ],
+ deps = [
+ ":absl_vlog_is_on",
+ ],
+)
+
# TODO(b/200695798): run this in TAP projects with -DABSL_MAX_VLOG_VERBOSITY={-100,100}
cc_test(
name = "vlog_is_on_test",
diff --git a/absl/log/CMakeLists.txt b/absl/log/CMakeLists.txt
index da855667..0ccda396 100644
--- a/absl/log/CMakeLists.txt
+++ b/absl/log/CMakeLists.txt
@@ -157,7 +157,7 @@ absl_cc_library(
absl::log_internal_conditions
absl::log_internal_message
absl::log_internal_strip
- absl::vlog_is_on
+ absl::absl_vlog_is_on
)
absl_cc_library(
@@ -419,7 +419,6 @@ absl_cc_library(
${ABSL_DEFAULT_LINKOPTS}
DEPS
absl::log_internal_log_impl
- absl::vlog_is_on
PUBLIC
)
@@ -698,16 +697,15 @@ absl_cc_library(
absl::optional
)
-
absl_cc_library(
NAME
- vlog_is_on
+ absl_vlog_is_on
COPTS
${ABSL_DEFAULT_COPTS}
LINKOPTS
${ABSL_DEFAULT_LINKOPTS}
HDRS
- "vlog_is_on.h"
+ "absl_vlog_is_on.h"
DEPS
absl::vlog_config_internal
absl::config
@@ -715,6 +713,19 @@ absl_cc_library(
absl::strings
)
+absl_cc_library(
+ NAME
+ vlog_is_on
+ COPTS
+ ${ABSL_DEFAULT_COPTS}
+ LINKOPTS
+ ${ABSL_DEFAULT_LINKOPTS}
+ HDRS
+ "vlog_is_on.h"
+ DEPS
+ absl::absl_vlog_is_on
+)
+
absl_cc_test(
NAME
vlog_is_on_test
diff --git a/absl/log/absl_vlog_is_on.h b/absl/log/absl_vlog_is_on.h
new file mode 100644
index 00000000..d1df2c0c
--- /dev/null
+++ b/absl/log/absl_vlog_is_on.h
@@ -0,0 +1,115 @@
+// Copyright 2022 The Abseil Authors.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// https://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// -----------------------------------------------------------------------------
+// File: log/absl_vlog_is_on.h
+// -----------------------------------------------------------------------------
+//
+// This header defines the `ABSL_VLOG_IS_ON()` macro that controls the
+// variable-verbosity conditional logging.
+//
+// It's used by `VLOG` in log.h, or it can also be used directly like this:
+//
+// if (ABSL_VLOG_IS_ON(2)) {
+// foo_server.RecomputeStatisticsExpensive();
+// LOG(INFO) << foo_server.LastStatisticsAsString();
+// }
+//
+// Each source file has an effective verbosity level that's a non-negative
+// integer computed from the `--vmodule` and `--v` flags.
+// `ABSL_VLOG_IS_ON(n)` is true, and `VLOG(n)` logs, if that effective verbosity
+// level is greater than or equal to `n`.
+//
+// `--vmodule` takes a comma-delimited list of key=value pairs. Each key is a
+// pattern matched against filenames, and the values give the effective severity
+// level applied to matching files. '?' and '*' characters in patterns are
+// interpreted as single-character and zero-or-more-character wildcards.
+// Patterns including a slash character are matched against full pathnames,
+// while those without are matched against basenames only. One suffix (i.e. the
+// last . and everything after it) is stripped from each filename prior to
+// matching, as is the special suffix "-inl".
+//
+// Files are matched against globs in `--vmodule` in order, and the first match
+// determines the verbosity level.
+//
+// Files which do not match any pattern in `--vmodule` use the value of `--v` as
+// their effective verbosity level. The default is 0.
+//
+// SetVLOGLevel helper function is provided to do limited dynamic control over
+// V-logging by appending to `--vmodule`. Because these go at the beginning of
+// the list, they take priority over any globs previously added.
+//
+// Resetting --vmodule will override all previous modifications to `--vmodule`,
+// including via SetVLOGLevel.
+
+#ifndef ABSL_LOG_ABSL_VLOG_IS_ON_H_
+#define ABSL_LOG_ABSL_VLOG_IS_ON_H_
+
+#include "absl/base/attributes.h"
+#include "absl/base/config.h"
+#include "absl/log/internal/vlog_config.h" // IWYU pragma: export
+#include "absl/strings/string_view.h"
+
+// IWYU pragma: private, include "absl/log/log.h"
+
+// This is expanded at the callsite to allow the compiler to optimize
+// always-false cases out of the build.
+// An ABSL_MAX_VLOG_VERBOSITY of 2 means that VLOG(3) and above should never
+// log.
+#ifdef ABSL_MAX_VLOG_VERBOSITY
+#define ABSL_LOG_INTERNAL_MAX_LOG_VERBOSITY_CHECK(x) \
+ ((x) <= ABSL_MAX_VLOG_VERBOSITY)&&
+#else
+#define ABSL_LOG_INTERNAL_MAX_LOG_VERBOSITY_CHECK(x)
+#endif
+
+// Each ABSL_VLOG_IS_ON call site gets its own VLogSite that registers with the
+// global linked list of sites to asynchronously update its verbosity level on
+// changes to --v or --vmodule. The verbosity can also be set by manually
+// calling SetVLOGLevel.
+//
+// ABSL_VLOG_IS_ON is not async signal safe, but it is guaranteed not to
+// allocate new memory.
+#define ABSL_VLOG_IS_ON(verbose_level) \
+ (ABSL_LOG_INTERNAL_MAX_LOG_VERBOSITY_CHECK(verbose_level)[]() \
+ ->::absl::log_internal::VLogSite * \
+ { \
+ ABSL_CONST_INIT static ::absl::log_internal::VLogSite site(__FILE__); \
+ return &site; \
+ }() \
+ ->IsEnabled(verbose_level))
+
+namespace absl {
+ABSL_NAMESPACE_BEGIN
+
+// Sets the global `(ABSL_)VLOG(_IS_ON)` level to `log_level`. This level is
+// applied to any sites whose filename doesn't match any `module_pattern`.
+// Returns the prior value.
+inline int SetGlobalVLogLevel(int log_level) {
+ return absl::log_internal::UpdateGlobalVLogLevel(log_level);
+}
+
+// Sets `(ABSL_)VLOG(_IS_ON)` level for `module_pattern` to `log_level`.
+// This lets us dynamically control what is normally set by the --vmodule flag.
+// Returns the level that previously applied to module_pattern.
+// Calling this with `log_level` of kUseFlag will have all sites for that
+// pattern use the value of --v.
+inline int SetVLogLevel(absl::string_view module_pattern, int log_level) {
+ return absl::log_internal::PrependVModule(module_pattern, log_level);
+}
+
+ABSL_NAMESPACE_END
+} // namespace absl
+
+#endif // ABSL_LOG_ABSL_VLOG_IS_ON_H_
diff --git a/absl/log/internal/BUILD.bazel b/absl/log/internal/BUILD.bazel
index 0525ac1d..1207737a 100644
--- a/absl/log/internal/BUILD.bazel
+++ b/absl/log/internal/BUILD.bazel
@@ -153,7 +153,7 @@ cc_library(
":conditions",
":log_message",
":strip",
- "//absl/log:vlog_is_on",
+ "//absl/log:absl_vlog_is_on",
],
)
diff --git a/absl/log/internal/log_impl.h b/absl/log/internal/log_impl.h
index ba90eda8..99de6dbb 100644
--- a/absl/log/internal/log_impl.h
+++ b/absl/log/internal/log_impl.h
@@ -15,10 +15,10 @@
#ifndef ABSL_LOG_INTERNAL_LOG_IMPL_H_
#define ABSL_LOG_INTERNAL_LOG_IMPL_H_
+#include "absl/log/absl_vlog_is_on.h"
#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) \
@@ -50,7 +50,7 @@
case 0: \
default: \
ABSL_LOG_INTERNAL_LOG_IF_IMPL( \
- _INFO, VLOG_IS_ON(absl_logging_internal_verbose_level)) \
+ _INFO, ABSL_VLOG_IS_ON(absl_logging_internal_verbose_level)) \
.WithVerbosity(absl_logging_internal_verbose_level)
#ifndef NDEBUG
@@ -59,15 +59,15 @@
case 0: \
default: \
ABSL_LOG_INTERNAL_LOG_IF_IMPL( \
- _INFO, VLOG_IS_ON(absl_logging_internal_verbose_level)) \
+ _INFO, ABSL_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)) \
+#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 && ABSL_VLOG_IS_ON(absl_logging_internal_verbose_level)) \
.WithVerbosity(absl_logging_internal_verbose_level)
#endif
@@ -169,7 +169,7 @@
case 0: \
default: \
ABSL_LOG_INTERNAL_CONDITION_INFO( \
- STATEFUL, VLOG_IS_ON(absl_logging_internal_verbose_level)) \
+ STATEFUL, ABSL_VLOG_IS_ON(absl_logging_internal_verbose_level)) \
(EveryN, n) ABSL_LOGGING_INTERNAL_LOG_INFO.InternalStream().WithVerbosity( \
absl_logging_internal_verbose_level)
@@ -178,7 +178,7 @@
case 0: \
default: \
ABSL_LOG_INTERNAL_CONDITION_INFO( \
- STATEFUL, VLOG_IS_ON(absl_logging_internal_verbose_level)) \
+ STATEFUL, ABSL_VLOG_IS_ON(absl_logging_internal_verbose_level)) \
(FirstN, n) ABSL_LOGGING_INTERNAL_LOG_INFO.InternalStream().WithVerbosity( \
absl_logging_internal_verbose_level)
@@ -187,7 +187,7 @@
case 0: \
default: \
ABSL_LOG_INTERNAL_CONDITION_INFO( \
- STATEFUL, VLOG_IS_ON(absl_logging_internal_verbose_level)) \
+ STATEFUL, ABSL_VLOG_IS_ON(absl_logging_internal_verbose_level)) \
(EveryPow2) ABSL_LOGGING_INTERNAL_LOG_INFO.InternalStream().WithVerbosity( \
absl_logging_internal_verbose_level)
@@ -196,7 +196,7 @@
case 0: \
default: \
ABSL_LOG_INTERNAL_CONDITION_INFO( \
- STATEFUL, VLOG_IS_ON(absl_logging_internal_verbose_level)) \
+ STATEFUL, ABSL_VLOG_IS_ON(absl_logging_internal_verbose_level)) \
(EveryNSec, n_seconds) ABSL_LOGGING_INTERNAL_LOG_INFO.InternalStream() \
.WithVerbosity(absl_logging_internal_verbose_level)
diff --git a/absl/log/vlog_is_on.h b/absl/log/vlog_is_on.h
index 4c929c30..f5c42477 100644
--- a/absl/log/vlog_is_on.h
+++ b/absl/log/vlog_is_on.h
@@ -56,23 +56,7 @@
#ifndef ABSL_LOG_VLOG_IS_ON_H_
#define ABSL_LOG_VLOG_IS_ON_H_
-#include "absl/base/attributes.h"
-#include "absl/base/config.h"
-#include "absl/log/internal/vlog_config.h" // IWYU pragma: export
-#include "absl/strings/string_view.h"
-
-// IWYU pragma: private, include "absl/log/log.h"
-
-// This is expanded at the callsite to allow the compiler to optimize
-// always-false cases out of the build.
-// An ABSL_MAX_VLOG_VERBOSITY of 2 means that VLOG(3) and above should never
-// log.
-#ifdef ABSL_MAX_VLOG_VERBOSITY
-#define ABSL_LOG_INTERNAL_MAX_LOG_VERBOSITY_CHECK(x) \
- ((x) <= ABSL_MAX_VLOG_VERBOSITY)&&
-#else
-#define ABSL_LOG_INTERNAL_MAX_LOG_VERBOSITY_CHECK(x)
-#endif
+#include "absl/log/absl_vlog_is_on.h" // IWYU pragma: export
// Each VLOG_IS_ON call site gets its own VLogSite that registers with the
// global linked list of sites to asynchronously update its verbosity level on
@@ -81,35 +65,6 @@
//
// VLOG_IS_ON is not async signal safe, but it is guaranteed not to allocate
// new memory.
-#define VLOG_IS_ON(verbose_level) \
- (ABSL_LOG_INTERNAL_MAX_LOG_VERBOSITY_CHECK(verbose_level)[]() \
- ->::absl::log_internal::VLogSite * \
- { \
- ABSL_CONST_INIT static ::absl::log_internal::VLogSite site(__FILE__); \
- return &site; \
- }() \
- ->IsEnabled(verbose_level))
-
-namespace absl {
-ABSL_NAMESPACE_BEGIN
-
-// Sets the global `VLOG(_IS_ON)` level to `log_level`. This level is applied
-// to any sites whose filename doesn't match any `module_pattern`. Returns the
-// prior value.
-inline int SetGlobalVLogLevel(int log_level) {
- return absl::log_internal::UpdateGlobalVLogLevel(log_level);
-}
-
-// Sets `VLOG(_IS_ON)` level for `module_pattern` to `log_level`.
-// This lets us dynamically control what is normally set by the --vmodule flag.
-// Returns the level that previously applied to module_pattern.
-// Calling this with `log_level` of kUseFlag will have all sites for that
-// pattern use the value of --v.
-inline int SetVLogLevel(absl::string_view module_pattern, int log_level) {
- return absl::log_internal::PrependVModule(module_pattern, log_level);
-}
-
-ABSL_NAMESPACE_END
-} // namespace absl
+#define VLOG_IS_ON(verbose_level) ABSL_VLOG_IS_ON(verbose_level)
#endif // ABSL_LOG_VLOG_IS_ON_H_