Commit b2dd3a5b by Derek Mauro Committed by Copybara-Service

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
parent 27134f25
...@@ -119,6 +119,7 @@ cc_library( ...@@ -119,6 +119,7 @@ cc_library(
"//absl/base:log_severity", "//absl/base:log_severity",
"//absl/base:raw_logging_internal", "//absl/base:raw_logging_internal",
"//absl/hash", "//absl/hash",
"//absl/log/internal:vlog_config",
"//absl/strings", "//absl/strings",
], ],
) )
...@@ -277,6 +278,7 @@ cc_test( ...@@ -277,6 +278,7 @@ cc_test(
linkopts = ABSL_DEFAULT_LINKOPTS, linkopts = ABSL_DEFAULT_LINKOPTS,
deps = [ deps = [
":flags", ":flags",
":globals",
":log", ":log",
":scoped_mock_log", ":scoped_mock_log",
":vlog_is_on", ":vlog_is_on",
......
...@@ -505,6 +505,7 @@ absl_cc_library( ...@@ -505,6 +505,7 @@ absl_cc_library(
absl::log_severity absl::log_severity
absl::raw_logging_internal absl::raw_logging_internal
absl::strings absl::strings
absl::vlog_config_internal
) )
absl_cc_library( absl_cc_library(
...@@ -737,8 +738,9 @@ absl_cc_test( ...@@ -737,8 +738,9 @@ absl_cc_test(
LINKOPTS LINKOPTS
${ABSL_DEFAULT_LINKOPTS} ${ABSL_DEFAULT_LINKOPTS}
DEPS DEPS
absl::log_flags
absl::log absl::log
absl::log_flags
absl::log_globals
absl::scoped_mock_log absl::scoped_mock_log
absl::vlog_is_on absl::vlog_is_on
absl::log_severity absl::log_severity
......
...@@ -90,26 +90,4 @@ ...@@ -90,26 +90,4 @@
}() \ }() \
->IsEnabled(verbose_level)) ->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_ #endif // ABSL_LOG_ABSL_VLOG_IS_ON_H_
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "absl/base/attributes.h" #include "absl/base/attributes.h"
#include "absl/base/config.h" #include "absl/base/config.h"
#include "absl/base/log_severity.h" #include "absl/base/log_severity.h"
#include "absl/log/internal/vlog_config.h"
#include "absl/strings/string_view.h" #include "absl/strings/string_view.h"
namespace absl { namespace absl {
...@@ -153,6 +154,28 @@ ABSL_MUST_USE_RESULT bool ShouldPrependLogPrefix(); ...@@ -153,6 +154,28 @@ ABSL_MUST_USE_RESULT bool ShouldPrependLogPrefix();
void EnableLogPrefix(bool on_off); 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 // Configure Android Native Log Tag
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// //
......
...@@ -88,6 +88,20 @@ TEST(TestGlobals, LogPrefix) { ...@@ -88,6 +88,20 @@ TEST(TestGlobals, LogPrefix) {
EXPECT_TRUE(absl::ShouldPrependLogPrefix()); 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) { TEST(TestGlobals, AndroidLogTag) {
// Verify invalid tags result in a check failure. // Verify invalid tags result in a check failure.
EXPECT_DEATH_IF_SUPPORTED(absl::SetAndroidNativeTag(nullptr), ".*"); EXPECT_DEATH_IF_SUPPORTED(absl::SetAndroidNativeTag(nullptr), ".*");
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "absl/base/log_severity.h" #include "absl/base/log_severity.h"
#include "absl/flags/flag.h" #include "absl/flags/flag.h"
#include "absl/log/flags.h" #include "absl/log/flags.h"
#include "absl/log/globals.h"
#include "absl/log/log.h" #include "absl/log/log.h"
#include "absl/log/scoped_mock_log.h" #include "absl/log/scoped_mock_log.h"
#include "absl/types/optional.h" #include "absl/types/optional.h"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment