Skip to content

Commit b2dd3a5

Browse files
derekmaurocopybara-github
authored andcommitted
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
1 parent 27134f2 commit b2dd3a5

File tree

6 files changed

+43
-23
lines changed

6 files changed

+43
-23
lines changed

absl/log/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ cc_library(
119119
"//absl/base:log_severity",
120120
"//absl/base:raw_logging_internal",
121121
"//absl/hash",
122+
"//absl/log/internal:vlog_config",
122123
"//absl/strings",
123124
],
124125
)
@@ -277,6 +278,7 @@ cc_test(
277278
linkopts = ABSL_DEFAULT_LINKOPTS,
278279
deps = [
279280
":flags",
281+
":globals",
280282
":log",
281283
":scoped_mock_log",
282284
":vlog_is_on",

absl/log/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,7 @@ absl_cc_library(
505505
absl::log_severity
506506
absl::raw_logging_internal
507507
absl::strings
508+
absl::vlog_config_internal
508509
)
509510

510511
absl_cc_library(
@@ -737,8 +738,9 @@ absl_cc_test(
737738
LINKOPTS
738739
${ABSL_DEFAULT_LINKOPTS}
739740
DEPS
740-
absl::log_flags
741741
absl::log
742+
absl::log_flags
743+
absl::log_globals
742744
absl::scoped_mock_log
743745
absl::vlog_is_on
744746
absl::log_severity

absl/log/absl_vlog_is_on.h

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -90,26 +90,4 @@
9090
}() \
9191
->IsEnabled(verbose_level))
9292

93-
namespace absl {
94-
ABSL_NAMESPACE_BEGIN
95-
96-
// Sets the global `(ABSL_)VLOG(_IS_ON)` level to `log_level`. This level is
97-
// applied to any sites whose filename doesn't match any `module_pattern`.
98-
// Returns the prior value.
99-
inline int SetGlobalVLogLevel(int log_level) {
100-
return absl::log_internal::UpdateGlobalVLogLevel(log_level);
101-
}
102-
103-
// Sets `(ABSL_)VLOG(_IS_ON)` level for `module_pattern` to `log_level`.
104-
// This lets us dynamically control what is normally set by the --vmodule flag.
105-
// Returns the level that previously applied to module_pattern.
106-
// Calling this with `log_level` of kUseFlag will have all sites for that
107-
// pattern use the value of --v.
108-
inline int SetVLogLevel(absl::string_view module_pattern, int log_level) {
109-
return absl::log_internal::PrependVModule(module_pattern, log_level);
110-
}
111-
112-
ABSL_NAMESPACE_END
113-
} // namespace absl
114-
11593
#endif // ABSL_LOG_ABSL_VLOG_IS_ON_H_

absl/log/globals.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "absl/base/attributes.h"
2525
#include "absl/base/config.h"
2626
#include "absl/base/log_severity.h"
27+
#include "absl/log/internal/vlog_config.h"
2728
#include "absl/strings/string_view.h"
2829

2930
namespace absl {
@@ -152,6 +153,28 @@ ABSL_MUST_USE_RESULT bool ShouldPrependLogPrefix();
152153
// This function is async-signal-safe.
153154
void EnableLogPrefix(bool on_off);
154155

156+
//------------------------------------------------------------------------------
157+
// Set Global VLOG Level
158+
//------------------------------------------------------------------------------
159+
//
160+
// Sets the global `(ABSL_)VLOG(_IS_ON)` level to `log_level`. This level is
161+
// applied to any sites whose filename doesn't match any `module_pattern`.
162+
// Returns the prior value.
163+
inline int SetGlobalVLogLevel(int log_level) {
164+
return absl::log_internal::UpdateGlobalVLogLevel(log_level);
165+
}
166+
167+
//------------------------------------------------------------------------------
168+
// Set VLOG Level
169+
//------------------------------------------------------------------------------
170+
//
171+
// Sets `(ABSL_)VLOG(_IS_ON)` level for `module_pattern` to `log_level`. This
172+
// allows programmatic control of what is normally set by the --vmodule flag.
173+
// Returns the level that previously applied to `module_pattern`.
174+
inline int SetVLogLevel(absl::string_view module_pattern, int log_level) {
175+
return absl::log_internal::PrependVModule(module_pattern, log_level);
176+
}
177+
155178
//------------------------------------------------------------------------------
156179
// Configure Android Native Log Tag
157180
//------------------------------------------------------------------------------

absl/log/globals_test.cc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,20 @@ TEST(TestGlobals, LogPrefix) {
8888
EXPECT_TRUE(absl::ShouldPrependLogPrefix());
8989
}
9090

91+
TEST(TestGlobals, SetGlobalVLogLevel) {
92+
EXPECT_EQ(absl::SetGlobalVLogLevel(42), 0);
93+
EXPECT_EQ(absl::SetGlobalVLogLevel(1337), 42);
94+
// Restore the value since it affects the default unset module value for
95+
// `SetVLogLevel()`.
96+
EXPECT_EQ(absl::SetGlobalVLogLevel(0), 1337);
97+
}
98+
99+
TEST(TestGlobals, SetVLogLevel) {
100+
EXPECT_EQ(absl::SetVLogLevel("setvloglevel", 42), 0);
101+
EXPECT_EQ(absl::SetVLogLevel("setvloglevel", 1337), 42);
102+
EXPECT_EQ(absl::SetVLogLevel("othersetvloglevel", 50), 0);
103+
}
104+
91105
TEST(TestGlobals, AndroidLogTag) {
92106
// Verify invalid tags result in a check failure.
93107
EXPECT_DEATH_IF_SUPPORTED(absl::SetAndroidNativeTag(nullptr), ".*");

absl/log/vlog_is_on_test.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "absl/base/log_severity.h"
2020
#include "absl/flags/flag.h"
2121
#include "absl/log/flags.h"
22+
#include "absl/log/globals.h"
2223
#include "absl/log/log.h"
2324
#include "absl/log/scoped_mock_log.h"
2425
#include "absl/types/optional.h"

0 commit comments

Comments
 (0)