aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDerek Mauro <dmauro@google.com>2024-01-13 08:39:43 -0800
committerCopybara-Service <copybara-worker@google.com>2024-01-13 08:40:35 -0800
commitb2dd3a5be797f8194bbc230c65f35aadd3998535 (patch)
treebb4351ad2564bca1e10aef1a8d6769890b747aed
parent27134f25b11e3119a2814988c3979fdc033e54e1 (diff)
downloadabseil-cpp-b2dd3a5be797f8194bbc230c65f35aadd3998535.tar.gz
Move absl::Set[Global]VLogLevel() to //absl/log/globals.h
For consistency, all global logging configurations lives in //absl/log/globals.h PiperOrigin-RevId: 598194040 Change-Id: I815b7d07f8fe06c70cef83bdf825c2f7ca504a2b
-rw-r--r--absl/log/BUILD.bazel2
-rw-r--r--absl/log/CMakeLists.txt4
-rw-r--r--absl/log/absl_vlog_is_on.h22
-rw-r--r--absl/log/globals.h23
-rw-r--r--absl/log/globals_test.cc14
-rw-r--r--absl/log/vlog_is_on_test.cc1
6 files changed, 43 insertions, 23 deletions
diff --git a/absl/log/BUILD.bazel b/absl/log/BUILD.bazel
index af23bb87..40e87cc9 100644
--- a/absl/log/BUILD.bazel
+++ b/absl/log/BUILD.bazel
@@ -119,6 +119,7 @@ cc_library(
"//absl/base:log_severity",
"//absl/base:raw_logging_internal",
"//absl/hash",
+ "//absl/log/internal:vlog_config",
"//absl/strings",
],
)
@@ -277,6 +278,7 @@ cc_test(
linkopts = ABSL_DEFAULT_LINKOPTS,
deps = [
":flags",
+ ":globals",
":log",
":scoped_mock_log",
":vlog_is_on",
diff --git a/absl/log/CMakeLists.txt b/absl/log/CMakeLists.txt
index 366d7bed..3c61fe87 100644
--- a/absl/log/CMakeLists.txt
+++ b/absl/log/CMakeLists.txt
@@ -505,6 +505,7 @@ absl_cc_library(
absl::log_severity
absl::raw_logging_internal
absl::strings
+ absl::vlog_config_internal
)
absl_cc_library(
@@ -737,8 +738,9 @@ absl_cc_test(
LINKOPTS
${ABSL_DEFAULT_LINKOPTS}
DEPS
- absl::log_flags
absl::log
+ absl::log_flags
+ absl::log_globals
absl::scoped_mock_log
absl::vlog_is_on
absl::log_severity
diff --git a/absl/log/absl_vlog_is_on.h b/absl/log/absl_vlog_is_on.h
index d1df2c0c..29096b48 100644
--- a/absl/log/absl_vlog_is_on.h
+++ b/absl/log/absl_vlog_is_on.h
@@ -90,26 +90,4 @@
}() \
->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/globals.h b/absl/log/globals.h
index bc3864c1..b36e47e6 100644
--- a/absl/log/globals.h
+++ b/absl/log/globals.h
@@ -24,6 +24,7 @@
#include "absl/base/attributes.h"
#include "absl/base/config.h"
#include "absl/base/log_severity.h"
+#include "absl/log/internal/vlog_config.h"
#include "absl/strings/string_view.h"
namespace absl {
@@ -153,6 +154,28 @@ ABSL_MUST_USE_RESULT bool ShouldPrependLogPrefix();
void EnableLogPrefix(bool on_off);
//------------------------------------------------------------------------------
+// Set Global VLOG Level
+//------------------------------------------------------------------------------
+//
+// 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);
+}
+
+//------------------------------------------------------------------------------
+// Set VLOG Level
+//------------------------------------------------------------------------------
+//
+// Sets `(ABSL_)VLOG(_IS_ON)` level for `module_pattern` to `log_level`. This
+// allows programmatic control of what is normally set by the --vmodule flag.
+// Returns the level that previously applied to `module_pattern`.
+inline int SetVLogLevel(absl::string_view module_pattern, int log_level) {
+ return absl::log_internal::PrependVModule(module_pattern, log_level);
+}
+
+//------------------------------------------------------------------------------
// Configure Android Native Log Tag
//------------------------------------------------------------------------------
//
diff --git a/absl/log/globals_test.cc b/absl/log/globals_test.cc
index 3d936cd7..0dc54d57 100644
--- a/absl/log/globals_test.cc
+++ b/absl/log/globals_test.cc
@@ -88,6 +88,20 @@ TEST(TestGlobals, LogPrefix) {
EXPECT_TRUE(absl::ShouldPrependLogPrefix());
}
+TEST(TestGlobals, SetGlobalVLogLevel) {
+ EXPECT_EQ(absl::SetGlobalVLogLevel(42), 0);
+ EXPECT_EQ(absl::SetGlobalVLogLevel(1337), 42);
+ // Restore the value since it affects the default unset module value for
+ // `SetVLogLevel()`.
+ EXPECT_EQ(absl::SetGlobalVLogLevel(0), 1337);
+}
+
+TEST(TestGlobals, SetVLogLevel) {
+ EXPECT_EQ(absl::SetVLogLevel("setvloglevel", 42), 0);
+ EXPECT_EQ(absl::SetVLogLevel("setvloglevel", 1337), 42);
+ EXPECT_EQ(absl::SetVLogLevel("othersetvloglevel", 50), 0);
+}
+
TEST(TestGlobals, AndroidLogTag) {
// Verify invalid tags result in a check failure.
EXPECT_DEATH_IF_SUPPORTED(absl::SetAndroidNativeTag(nullptr), ".*");
diff --git a/absl/log/vlog_is_on_test.cc b/absl/log/vlog_is_on_test.cc
index 28a2eea1..883d798e 100644
--- a/absl/log/vlog_is_on_test.cc
+++ b/absl/log/vlog_is_on_test.cc
@@ -19,6 +19,7 @@
#include "absl/base/log_severity.h"
#include "absl/flags/flag.h"
#include "absl/log/flags.h"
+#include "absl/log/globals.h"
#include "absl/log/log.h"
#include "absl/log/scoped_mock_log.h"
#include "absl/types/optional.h"