Skip to content

Commit de292e8

Browse files
derekmaurocopybara-github
authored andcommitted
Add a log severity alias DO_NOT_$UBMIT intended for logging during development
'S' should be replace with S, in DO_NOT_$UBMIT :-) `DO_NOT_$UBMIT` is an alias for `ERROR`, and is the right level to use when you are using `LOG` for what's often called `printf()` debugging. The name is easy to spot in review and is caught by common (but not on-by-default) presubmit checks. The contract is that **it must not be checked in**, so the Abseil team reserves the right to delete it, change what it does, and/or scrub any instances that do end up checked in, with or without notice. Git users could consider adding a pre-commit hook to reject the string "DO_NOT_$UBMIT" to use this feature. https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks PiperOrigin-RevId: 738364247 Change-Id: I3a277a941e7735ebf64b8da641bd42ca4830df9c
1 parent 310e6f4 commit de292e8

File tree

4 files changed

+50
-1
lines changed

4 files changed

+50
-1
lines changed

absl/log/internal/conditions.h

+4
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@
118118
ABSL_LOG_INTERNAL_##type##_CONDITION( \
119119
(condition) && ::absl::LogSeverity::kError >= \
120120
static_cast<::absl::LogSeverity>(ABSL_MIN_LOG_LEVEL))
121+
#define ABSL_LOG_INTERNAL_CONDITION_DO_NOT_SUBMIT(type, condition) \
122+
ABSL_LOG_INTERNAL_CONDITION_ERROR(type, condition)
121123
// NOTE: Use ternary operators instead of short-circuiting to mitigate
122124
// https://bugs.llvm.org/show_bug.cgi?id=51928.
123125
#define ABSL_LOG_INTERNAL_CONDITION_FATAL(type, condition) \
@@ -169,6 +171,8 @@
169171
ABSL_LOG_INTERNAL_##type##_CONDITION(condition)
170172
#define ABSL_LOG_INTERNAL_CONDITION_ERROR(type, condition) \
171173
ABSL_LOG_INTERNAL_##type##_CONDITION(condition)
174+
#define ABSL_LOG_INTERNAL_CONDITION_DO_NOT_SUBMIT(type, condition) \
175+
ABSL_LOG_INTERNAL_CONDITION_ERROR(type, condition)
172176
#define ABSL_LOG_INTERNAL_CONDITION_FATAL(type, condition) \
173177
ABSL_LOG_INTERNAL_##type##_CONDITION(condition)
174178
#define ABSL_LOG_INTERNAL_CONDITION_QFATAL(type, condition) \

absl/log/internal/strip.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
// -----------------------------------------------------------------------------
1616
// File: log/internal/strip.h
1717
// -----------------------------------------------------------------------------
18-
//
18+
19+
// SKIP_ABSL_INLINE_NAMESPACE_CHECK
1920

2021
#ifndef ABSL_LOG_INTERNAL_STRIP_H_
2122
#define ABSL_LOG_INTERNAL_STRIP_H_
@@ -94,4 +95,6 @@
9495
#define ABSL_LOGGING_INTERNAL_DLOG_DFATAL ABSL_LOGGING_INTERNAL_LOG_DFATAL
9596
#define ABSL_LOGGING_INTERNAL_DLOG_LEVEL ABSL_LOGGING_INTERNAL_LOG_LEVEL
9697

98+
#define ABSL_LOGGING_INTERNAL_LOG_DO_NOT_SUBMIT ABSL_LOGGING_INTERNAL_LOG_ERROR
99+
97100
#endif // ABSL_LOG_INTERNAL_STRIP_H_

absl/log/log.h

+9
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@
3434
// running registered error handlers.
3535
// * The `DFATAL` pseudo-severity level is defined as `FATAL` in debug mode and
3636
// as `ERROR` otherwise.
37+
// * The `DO_NOT_SUBMIT` pseudo-severity level is an alias for `ERROR`, and is
38+
// intended for debugging statements that won't be submitted. The name is
39+
// chosen to be easy to spot in review and with tools in order to ensure that
40+
// such statements aren't inadvertently checked in.
41+
// The contract is that **it may not be checked in**, meaning that no
42+
// in-contract uses will be affected if we decide in the future to remove it
43+
// or change what it does.
3744
// Some preprocessor shenanigans are used to ensure that e.g. `LOG(INFO)` has
3845
// the same meaning even if a local symbol or preprocessor macro named `INFO` is
3946
// defined. To specify a severity level using an expression instead of a
@@ -194,6 +201,8 @@
194201
// LOG(INFO) << std::hex << 0xdeadbeef; // logs "0xdeadbeef"
195202
// LOG(INFO) << 0xdeadbeef; // logs "3735928559"
196203

204+
// SKIP_ABSL_INLINE_NAMESPACE_CHECK
205+
197206
#ifndef ABSL_LOG_LOG_H_
198207
#define ABSL_LOG_LOG_H_
199208

absl/log/log_basic_test_impl.inc

+33
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
// See the License for the specific language governing permissions and
1414
// limitations under the License.
1515

16+
// SKIP_ABSL_INLINE_NAMESPACE_CHECK
17+
1618
// The testcases in this file are expected to pass or be skipped with any value
1719
// of ABSL_MIN_LOG_LEVEL
1820

@@ -181,6 +183,37 @@ TEST_P(BasicLogTest, Error) {
181183
do_log();
182184
}
183185

186+
TEST_P(BasicLogTest, DoNotSubmit) {
187+
absl::log_internal::ScopedMinLogLevel scoped_min_log_level(GetParam());
188+
189+
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
190+
191+
const int log_line = __LINE__ + 1;
192+
auto do_log = [] { ABSL_TEST_LOG(DO_NOT_SUBMIT) << "hello world"; };
193+
194+
if (LoggingEnabledAt(absl::LogSeverity::kError)) {
195+
EXPECT_CALL(
196+
test_sink,
197+
Send(AllOf(
198+
SourceFilename(Eq(__FILE__)),
199+
SourceBasename(Eq("log_basic_test_impl.inc")),
200+
SourceLine(Eq(log_line)), Prefix(IsTrue()),
201+
LogSeverity(Eq(absl::LogSeverity::kError)),
202+
Timestamp(InMatchWindow()),
203+
ThreadID(Eq(absl::base_internal::GetTID())),
204+
TextMessage(Eq("hello world")),
205+
Verbosity(Eq(absl::LogEntry::kNoVerbosityLevel)),
206+
ENCODED_MESSAGE(MatchesEvent(
207+
Eq(__FILE__), Eq(log_line), InMatchWindow(),
208+
Eq(logging::proto::ERROR), Eq(absl::base_internal::GetTID()),
209+
ElementsAre(ValueWithLiteral(Eq("hello world"))))),
210+
Stacktrace(IsEmpty()))));
211+
}
212+
213+
test_sink.StartCapturingLogs();
214+
do_log();
215+
}
216+
184217
#if GTEST_HAS_DEATH_TEST
185218
using BasicLogDeathTest = BasicLogTest;
186219

0 commit comments

Comments
 (0)