Commit a99a183c by Mike Kruskal Committed by Copybara-Service

Move implementations of absl logging to an internal file.

This will allow us to create ABSL_-prefixed variants with shared implementation.

PiperOrigin-RevId: 493383908
Change-Id: I3529021df7afa642fadaf43eb9fd8249e9202758
parent 6dab0bd9
...@@ -32,7 +32,7 @@ cc_library( ...@@ -32,7 +32,7 @@ cc_library(
copts = ABSL_DEFAULT_COPTS, copts = ABSL_DEFAULT_COPTS,
linkopts = ABSL_DEFAULT_LINKOPTS, linkopts = ABSL_DEFAULT_LINKOPTS,
deps = [ deps = [
"//absl/base:core_headers", "//absl/log/internal:check_impl",
"//absl/log/internal:check_op", "//absl/log/internal:check_op",
"//absl/log/internal:conditions", "//absl/log/internal:conditions",
"//absl/log/internal:log_message", "//absl/log/internal:log_message",
...@@ -114,9 +114,7 @@ cc_library( ...@@ -114,9 +114,7 @@ cc_library(
copts = ABSL_DEFAULT_COPTS, copts = ABSL_DEFAULT_COPTS,
linkopts = ABSL_DEFAULT_LINKOPTS, linkopts = ABSL_DEFAULT_LINKOPTS,
deps = [ deps = [
"//absl/log/internal:conditions", "//absl/log/internal:log_impl",
"//absl/log/internal:log_message",
"//absl/log/internal:strip",
], ],
) )
......
...@@ -17,6 +17,24 @@ ...@@ -17,6 +17,24 @@
# Internal targets # Internal targets
absl_cc_library( absl_cc_library(
NAME NAME
log_internal_check_impl
SRCS
HDRS
"internal/check_impl.h"
COPTS
${ABSL_DEFAULT_COPTS}
LINKOPTS
${ABSL_DEFAULT_LINKOPTS}
DEPS
absl::core_headers
absl::log_internal_check_op
absl::log_internal_conditions
absl::log_internal_message
absl::log_internal_strip
)
absl_cc_library(
NAME
log_internal_check_op log_internal_check_op
SRCS SRCS
"internal/check_op.cc" "internal/check_op.cc"
...@@ -128,6 +146,22 @@ absl_cc_library( ...@@ -128,6 +146,22 @@ absl_cc_library(
absl_cc_library( absl_cc_library(
NAME NAME
log_internal_log_impl
SRCS
HDRS
"internal/log_impl.h"
COPTS
${ABSL_DEFAULT_COPTS}
LINKOPTS
${ABSL_DEFAULT_LINKOPTS}
DEPS
absl::log_internal_conditions
absl::log_internal_message
absl::log_internal_strip
)
absl_cc_library(
NAME
log_internal_proto log_internal_proto
SRCS SRCS
"internal/proto.cc" "internal/proto.cc"
...@@ -366,6 +400,7 @@ absl_cc_library( ...@@ -366,6 +400,7 @@ absl_cc_library(
LINKOPTS LINKOPTS
${ABSL_DEFAULT_LINKOPTS} ${ABSL_DEFAULT_LINKOPTS}
DEPS DEPS
absl::log_internal_check_impl
absl::core_headers absl::core_headers
absl::log_internal_check_op absl::log_internal_check_op
absl::log_internal_conditions absl::log_internal_conditions
...@@ -467,9 +502,7 @@ absl_cc_library( ...@@ -467,9 +502,7 @@ absl_cc_library(
LINKOPTS LINKOPTS
${ABSL_DEFAULT_LINKOPTS} ${ABSL_DEFAULT_LINKOPTS}
DEPS DEPS
absl::log_internal_conditions absl::log_internal_log_impl
absl::log_internal_message
absl::log_internal_strip
PUBLIC PUBLIC
) )
......
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
#ifndef ABSL_LOG_CHECK_H_ #ifndef ABSL_LOG_CHECK_H_
#define ABSL_LOG_CHECK_H_ #define ABSL_LOG_CHECK_H_
#include "absl/base/optimization.h" #include "absl/log/internal/check_impl.h"
#include "absl/log/internal/check_op.h" // IWYU pragma: export #include "absl/log/internal/check_op.h" // IWYU pragma: export
#include "absl/log/internal/conditions.h" // IWYU pragma: export #include "absl/log/internal/conditions.h" // IWYU pragma: export
#include "absl/log/internal/log_message.h" // IWYU pragma: export #include "absl/log/internal/log_message.h" // IWYU pragma: export
...@@ -54,10 +54,7 @@ ...@@ -54,10 +54,7 @@
// Might produce a message like: // Might produce a message like:
// //
// Check failed: !cheese.empty() Out of Cheese // Check failed: !cheese.empty() Out of Cheese
#define CHECK(condition) \ #define CHECK(condition) ABSL_CHECK_IMPL(condition)
ABSL_LOG_INTERNAL_CONDITION_FATAL(STATELESS, \
ABSL_PREDICT_FALSE(!(condition))) \
ABSL_LOG_INTERNAL_CHECK(#condition).InternalStream()
// QCHECK() // QCHECK()
// //
...@@ -65,10 +62,7 @@ ...@@ -65,10 +62,7 @@
// not run registered error handlers (as `QFATAL`). It is useful when the // not run registered error handlers (as `QFATAL`). It is useful when the
// problem is definitely unrelated to program flow, e.g. when validating user // problem is definitely unrelated to program flow, e.g. when validating user
// input. // input.
#define QCHECK(condition) \ #define QCHECK(condition) ABSL_QCHECK_IMPL(condition)
ABSL_LOG_INTERNAL_CONDITION_QFATAL(STATELESS, \
ABSL_PREDICT_FALSE(!(condition))) \
ABSL_LOG_INTERNAL_QCHECK(#condition).InternalStream()
// PCHECK() // PCHECK()
// //
...@@ -83,7 +77,7 @@ ...@@ -83,7 +77,7 @@
// Might produce a message like: // Might produce a message like:
// //
// Check failed: fd != -1 posix is difficult: No such file or directory [2] // Check failed: fd != -1 posix is difficult: No such file or directory [2]
#define PCHECK(condition) CHECK(condition).WithPerror() #define PCHECK(condition) ABSL_PCHECK_IMPL(condition)
// DCHECK() // DCHECK()
// //
...@@ -91,11 +85,7 @@ ...@@ -91,11 +85,7 @@
// `DLOG`). Unlike with `CHECK` (but as with `assert`), it is not safe to rely // `DLOG`). Unlike with `CHECK` (but as with `assert`), it is not safe to rely
// on evaluation of `condition`: when `NDEBUG` is enabled, DCHECK does not // on evaluation of `condition`: when `NDEBUG` is enabled, DCHECK does not
// evaluate the condition. // evaluate the condition.
#ifndef NDEBUG #define DCHECK(condition) ABSL_DCHECK_IMPL(condition)
#define DCHECK(condition) CHECK(condition)
#else
#define DCHECK(condition) CHECK(true || (condition))
#endif
// `CHECK_EQ` and friends are syntactic sugar for `CHECK(x == y)` that // `CHECK_EQ` and friends are syntactic sugar for `CHECK(x == y)` that
// automatically output the expression being tested and the evaluated values on // automatically output the expression being tested and the evaluated values on
...@@ -123,43 +113,24 @@ ...@@ -123,43 +113,24 @@
// //
// WARNING: Passing `NULL` as an argument to `CHECK_EQ` and similar macros does // WARNING: Passing `NULL` as an argument to `CHECK_EQ` and similar macros does
// not compile. Use `nullptr` instead. // not compile. Use `nullptr` instead.
#define CHECK_EQ(val1, val2) \ #define CHECK_EQ(val1, val2) ABSL_CHECK_EQ_IMPL(val1, val2)
ABSL_LOG_INTERNAL_CHECK_OP(Check_EQ, ==, val1, val2) #define CHECK_NE(val1, val2) ABSL_CHECK_NE_IMPL(val1, val2)
#define CHECK_NE(val1, val2) \ #define CHECK_LE(val1, val2) ABSL_CHECK_LE_IMPL(val1, val2)
ABSL_LOG_INTERNAL_CHECK_OP(Check_NE, !=, val1, val2) #define CHECK_LT(val1, val2) ABSL_CHECK_LT_IMPL(val1, val2)
#define CHECK_LE(val1, val2) \ #define CHECK_GE(val1, val2) ABSL_CHECK_GE_IMPL(val1, val2)
ABSL_LOG_INTERNAL_CHECK_OP(Check_LE, <=, val1, val2) #define CHECK_GT(val1, val2) ABSL_CHECK_GT_IMPL(val1, val2)
#define CHECK_LT(val1, val2) ABSL_LOG_INTERNAL_CHECK_OP(Check_LT, <, val1, val2) #define QCHECK_EQ(val1, val2) ABSL_QCHECK_EQ_IMPL(val1, val2)
#define CHECK_GE(val1, val2) \ #define QCHECK_NE(val1, val2) ABSL_QCHECK_NE_IMPL(val1, val2)
ABSL_LOG_INTERNAL_CHECK_OP(Check_GE, >=, val1, val2) #define QCHECK_LE(val1, val2) ABSL_QCHECK_LE_IMPL(val1, val2)
#define CHECK_GT(val1, val2) ABSL_LOG_INTERNAL_CHECK_OP(Check_GT, >, val1, val2) #define QCHECK_LT(val1, val2) ABSL_QCHECK_LT_IMPL(val1, val2)
#define QCHECK_EQ(val1, val2) \ #define QCHECK_GE(val1, val2) ABSL_QCHECK_GE_IMPL(val1, val2)
ABSL_LOG_INTERNAL_QCHECK_OP(Check_EQ, ==, val1, val2) #define QCHECK_GT(val1, val2) ABSL_QCHECK_GT_IMPL(val1, val2)
#define QCHECK_NE(val1, val2) \ #define DCHECK_EQ(val1, val2) ABSL_DCHECK_EQ_IMPL(val1, val2)
ABSL_LOG_INTERNAL_QCHECK_OP(Check_NE, !=, val1, val2) #define DCHECK_NE(val1, val2) ABSL_DCHECK_NE_IMPL(val1, val2)
#define QCHECK_LE(val1, val2) \ #define DCHECK_LE(val1, val2) ABSL_DCHECK_LE_IMPL(val1, val2)
ABSL_LOG_INTERNAL_QCHECK_OP(Check_LE, <=, val1, val2) #define DCHECK_LT(val1, val2) ABSL_DCHECK_LT_IMPL(val1, val2)
#define QCHECK_LT(val1, val2) \ #define DCHECK_GE(val1, val2) ABSL_DCHECK_GE_IMPL(val1, val2)
ABSL_LOG_INTERNAL_QCHECK_OP(Check_LT, <, val1, val2) #define DCHECK_GT(val1, val2) ABSL_DCHECK_GT_IMPL(val1, val2)
#define QCHECK_GE(val1, val2) \
ABSL_LOG_INTERNAL_QCHECK_OP(Check_GE, >=, val1, val2)
#define QCHECK_GT(val1, val2) \
ABSL_LOG_INTERNAL_QCHECK_OP(Check_GT, >, val1, val2)
#ifndef NDEBUG
#define DCHECK_EQ(val1, val2) CHECK_EQ(val1, val2)
#define DCHECK_NE(val1, val2) CHECK_NE(val1, val2)
#define DCHECK_LE(val1, val2) CHECK_LE(val1, val2)
#define DCHECK_LT(val1, val2) CHECK_LT(val1, val2)
#define DCHECK_GE(val1, val2) CHECK_GE(val1, val2)
#define DCHECK_GT(val1, val2) CHECK_GT(val1, val2)
#else // ndef NDEBUG
#define DCHECK_EQ(val1, val2) ABSL_LOG_INTERNAL_DCHECK_NOP(val1, val2)
#define DCHECK_NE(val1, val2) ABSL_LOG_INTERNAL_DCHECK_NOP(val1, val2)
#define DCHECK_LE(val1, val2) ABSL_LOG_INTERNAL_DCHECK_NOP(val1, val2)
#define DCHECK_LT(val1, val2) ABSL_LOG_INTERNAL_DCHECK_NOP(val1, val2)
#define DCHECK_GE(val1, val2) ABSL_LOG_INTERNAL_DCHECK_NOP(val1, val2)
#define DCHECK_GT(val1, val2) ABSL_LOG_INTERNAL_DCHECK_NOP(val1, val2)
#endif // def NDEBUG
// `CHECK_OK` and friends validate that the provided `absl::Status` or // `CHECK_OK` and friends validate that the provided `absl::Status` or
// `absl::StatusOr<T>` is OK. If it isn't, they print a failure message that // `absl::StatusOr<T>` is OK. If it isn't, they print a failure message that
...@@ -175,13 +146,9 @@ ...@@ -175,13 +146,9 @@
// Might produce a message like: // Might produce a message like:
// //
// Check failed: FunctionReturnsStatus(x, y, z) is OK (ABORTED: timeout) oops! // Check failed: FunctionReturnsStatus(x, y, z) is OK (ABORTED: timeout) oops!
#define CHECK_OK(status) ABSL_LOG_INTERNAL_CHECK_OK(status) #define CHECK_OK(status) ABSL_CHECK_OK_IMPL(status)
#define QCHECK_OK(status) ABSL_LOG_INTERNAL_QCHECK_OK(status) #define QCHECK_OK(status) ABSL_QCHECK_OK_IMPL(status)
#ifndef NDEBUG #define DCHECK_OK(status) ABSL_DCHECK_OK_IMPL(status)
#define DCHECK_OK(status) ABSL_LOG_INTERNAL_CHECK_OK(status)
#else
#define DCHECK_OK(status) ABSL_LOG_INTERNAL_DCHECK_NOP(status, nullptr)
#endif
// `CHECK_STREQ` and friends provide `CHECK_EQ` functionality for C strings, // `CHECK_STREQ` and friends provide `CHECK_EQ` functionality for C strings,
// i.e., nul-terminated char arrays. The `CASE` versions are case-insensitive. // i.e., nul-terminated char arrays. The `CASE` versions are case-insensitive.
...@@ -196,32 +163,17 @@ ...@@ -196,32 +163,17 @@
// Example: // Example:
// //
// CHECK_STREQ(Foo().c_str(), Bar().c_str()); // CHECK_STREQ(Foo().c_str(), Bar().c_str());
#define CHECK_STREQ(s1, s2) \ #define CHECK_STREQ(s1, s2) ABSL_CHECK_STREQ_IMPL(s1, s2)
ABSL_LOG_INTERNAL_CHECK_STROP(strcmp, ==, true, s1, s2) #define CHECK_STRNE(s1, s2) ABSL_CHECK_STRNE_IMPL(s1, s2)
#define CHECK_STRNE(s1, s2) \ #define CHECK_STRCASEEQ(s1, s2) ABSL_CHECK_STRCASEEQ_IMPL(s1, s2)
ABSL_LOG_INTERNAL_CHECK_STROP(strcmp, !=, false, s1, s2) #define CHECK_STRCASENE(s1, s2) ABSL_CHECK_STRCASENE_IMPL(s1, s2)
#define CHECK_STRCASEEQ(s1, s2) \ #define QCHECK_STREQ(s1, s2) ABSL_QCHECK_STREQ_IMPL(s1, s2)
ABSL_LOG_INTERNAL_CHECK_STROP(strcasecmp, ==, true, s1, s2) #define QCHECK_STRNE(s1, s2) ABSL_QCHECK_STRNE_IMPL(s1, s2)
#define CHECK_STRCASENE(s1, s2) \ #define QCHECK_STRCASEEQ(s1, s2) ABSL_QCHECK_STRCASEEQ_IMPL(s1, s2)
ABSL_LOG_INTERNAL_CHECK_STROP(strcasecmp, !=, false, s1, s2) #define QCHECK_STRCASENE(s1, s2) ABSL_QCHECK_STRCASENE_IMPL(s1, s2)
#define QCHECK_STREQ(s1, s2) \ #define DCHECK_STREQ(s1, s2) ABSL_DCHECK_STREQ_IMPL(s1, s2)
ABSL_LOG_INTERNAL_QCHECK_STROP(strcmp, ==, true, s1, s2) #define DCHECK_STRNE(s1, s2) ABSL_DCHECK_STRNE_IMPL(s1, s2)
#define QCHECK_STRNE(s1, s2) \ #define DCHECK_STRCASEEQ(s1, s2) ABSL_DCHECK_STRCASEEQ_IMPL(s1, s2)
ABSL_LOG_INTERNAL_QCHECK_STROP(strcmp, !=, false, s1, s2) #define DCHECK_STRCASENE(s1, s2) ABSL_DCHECK_STRCASENE_IMPL(s1, s2)
#define QCHECK_STRCASEEQ(s1, s2) \
ABSL_LOG_INTERNAL_QCHECK_STROP(strcasecmp, ==, true, s1, s2)
#define QCHECK_STRCASENE(s1, s2) \
ABSL_LOG_INTERNAL_QCHECK_STROP(strcasecmp, !=, false, s1, s2)
#ifndef NDEBUG
#define DCHECK_STREQ(s1, s2) CHECK_STREQ(s1, s2)
#define DCHECK_STRCASEEQ(s1, s2) CHECK_STRCASEEQ(s1, s2)
#define DCHECK_STRNE(s1, s2) CHECK_STRNE(s1, s2)
#define DCHECK_STRCASENE(s1, s2) CHECK_STRCASENE(s1, s2)
#else // ndef NDEBUG
#define DCHECK_STREQ(s1, s2) ABSL_LOG_INTERNAL_DCHECK_NOP(s1, s2)
#define DCHECK_STRCASEEQ(s1, s2) ABSL_LOG_INTERNAL_DCHECK_NOP(s1, s2)
#define DCHECK_STRNE(s1, s2) ABSL_LOG_INTERNAL_DCHECK_NOP(s1, s2)
#define DCHECK_STRCASENE(s1, s2) ABSL_LOG_INTERNAL_DCHECK_NOP(s1, s2)
#endif // def NDEBUG
#endif // ABSL_LOG_CHECK_H_ #endif // ABSL_LOG_CHECK_H_
...@@ -28,6 +28,20 @@ package(default_visibility = [ ...@@ -28,6 +28,20 @@ package(default_visibility = [
licenses(["notice"]) licenses(["notice"])
cc_library( cc_library(
name = "check_impl",
hdrs = ["check_impl.h"],
copts = ABSL_DEFAULT_COPTS,
linkopts = ABSL_DEFAULT_LINKOPTS,
deps = [
":check_op",
":conditions",
":log_message",
":strip",
"//absl/base:core_headers",
],
)
cc_library(
name = "check_op", name = "check_op",
srcs = ["check_op.cc"], srcs = ["check_op.cc"],
hdrs = ["check_op.h"], hdrs = ["check_op.h"],
...@@ -124,6 +138,18 @@ cc_library( ...@@ -124,6 +138,18 @@ cc_library(
) )
cc_library( cc_library(
name = "log_impl",
hdrs = ["log_impl.h"],
copts = ABSL_DEFAULT_COPTS,
linkopts = ABSL_DEFAULT_LINKOPTS,
deps = [
":conditions",
":log_message",
":strip",
],
)
cc_library(
name = "log_message", name = "log_message",
srcs = ["log_message.cc"], srcs = ["log_message.cc"],
hdrs = ["log_message.h"], hdrs = ["log_message.h"],
......
// 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.
#ifndef ABSL_LOG_INTERNAL_CHECK_IMPL_H_
#define ABSL_LOG_INTERNAL_CHECK_IMPL_H_
#include "absl/base/optimization.h"
#include "absl/log/internal/check_op.h"
#include "absl/log/internal/conditions.h"
#include "absl/log/internal/log_message.h"
#include "absl/log/internal/strip.h"
// CHECK
#define ABSL_CHECK_IMPL(condition) \
ABSL_LOG_INTERNAL_CONDITION_FATAL(STATELESS, \
ABSL_PREDICT_FALSE(!(condition))) \
ABSL_LOG_INTERNAL_CHECK(#condition).InternalStream()
#define ABSL_QCHECK_IMPL(condition) \
ABSL_LOG_INTERNAL_CONDITION_QFATAL(STATELESS, \
ABSL_PREDICT_FALSE(!(condition))) \
ABSL_LOG_INTERNAL_QCHECK(#condition).InternalStream()
#define ABSL_PCHECK_IMPL(condition) ABSL_CHECK_IMPL(condition).WithPerror()
#ifndef NDEBUG
#define ABSL_DCHECK_IMPL(condition) ABSL_CHECK_IMPL(condition)
#else
#define ABSL_DCHECK_IMPL(condition) ABSL_CHECK_IMPL(true || (condition))
#endif
// CHECK_EQ
#define ABSL_CHECK_EQ_IMPL(val1, val2) \
ABSL_LOG_INTERNAL_CHECK_OP(Check_EQ, ==, val1, val2)
#define ABSL_CHECK_NE_IMPL(val1, val2) \
ABSL_LOG_INTERNAL_CHECK_OP(Check_NE, !=, val1, val2)
#define ABSL_CHECK_LE_IMPL(val1, val2) \
ABSL_LOG_INTERNAL_CHECK_OP(Check_LE, <=, val1, val2)
#define ABSL_CHECK_LT_IMPL(val1, val2) \
ABSL_LOG_INTERNAL_CHECK_OP(Check_LT, <, val1, val2)
#define ABSL_CHECK_GE_IMPL(val1, val2) \
ABSL_LOG_INTERNAL_CHECK_OP(Check_GE, >=, val1, val2)
#define ABSL_CHECK_GT_IMPL(val1, val2) \
ABSL_LOG_INTERNAL_CHECK_OP(Check_GT, >, val1, val2)
#define ABSL_QCHECK_EQ_IMPL(val1, val2) \
ABSL_LOG_INTERNAL_QCHECK_OP(Check_EQ, ==, val1, val2)
#define ABSL_QCHECK_NE_IMPL(val1, val2) \
ABSL_LOG_INTERNAL_QCHECK_OP(Check_NE, !=, val1, val2)
#define ABSL_QCHECK_LE_IMPL(val1, val2) \
ABSL_LOG_INTERNAL_QCHECK_OP(Check_LE, <=, val1, val2)
#define ABSL_QCHECK_LT_IMPL(val1, val2) \
ABSL_LOG_INTERNAL_QCHECK_OP(Check_LT, <, val1, val2)
#define ABSL_QCHECK_GE_IMPL(val1, val2) \
ABSL_LOG_INTERNAL_QCHECK_OP(Check_GE, >=, val1, val2)
#define ABSL_QCHECK_GT_IMPL(val1, val2) \
ABSL_LOG_INTERNAL_QCHECK_OP(Check_GT, >, val1, val2)
#ifndef NDEBUG
#define ABSL_DCHECK_EQ_IMPL(val1, val2) ABSL_CHECK_EQ_IMPL(val1, val2)
#define ABSL_DCHECK_NE_IMPL(val1, val2) ABSL_CHECK_NE_IMPL(val1, val2)
#define ABSL_DCHECK_LE_IMPL(val1, val2) ABSL_CHECK_LE_IMPL(val1, val2)
#define ABSL_DCHECK_LT_IMPL(val1, val2) ABSL_CHECK_LT_IMPL(val1, val2)
#define ABSL_DCHECK_GE_IMPL(val1, val2) ABSL_CHECK_GE_IMPL(val1, val2)
#define ABSL_DCHECK_GT_IMPL(val1, val2) ABSL_CHECK_GT_IMPL(val1, val2)
#else // ndef NDEBUG
#define ABSL_DCHECK_EQ_IMPL(val1, val2) ABSL_LOG_INTERNAL_DCHECK_NOP(val1, val2)
#define ABSL_DCHECK_NE_IMPL(val1, val2) ABSL_LOG_INTERNAL_DCHECK_NOP(val1, val2)
#define ABSL_DCHECK_LE_IMPL(val1, val2) ABSL_LOG_INTERNAL_DCHECK_NOP(val1, val2)
#define ABSL_DCHECK_LT_IMPL(val1, val2) ABSL_LOG_INTERNAL_DCHECK_NOP(val1, val2)
#define ABSL_DCHECK_GE_IMPL(val1, val2) ABSL_LOG_INTERNAL_DCHECK_NOP(val1, val2)
#define ABSL_DCHECK_GT_IMPL(val1, val2) ABSL_LOG_INTERNAL_DCHECK_NOP(val1, val2)
#endif // def NDEBUG
// CHECK_OK
#define ABSL_CHECK_OK_IMPL(status) ABSL_LOG_INTERNAL_CHECK_OK(status)
#define ABSL_QCHECK_OK_IMPL(status) ABSL_LOG_INTERNAL_QCHECK_OK(status)
#ifndef NDEBUG
#define ABSL_DCHECK_OK_IMPL(status) ABSL_LOG_INTERNAL_CHECK_OK(status)
#else
#define ABSL_DCHECK_OK_IMPL(status) \
ABSL_LOG_INTERNAL_DCHECK_NOP(status, nullptr)
#endif
// CHECK_STREQ
#define ABSL_CHECK_STREQ_IMPL(s1, s2) \
ABSL_LOG_INTERNAL_CHECK_STROP(strcmp, ==, true, s1, s2)
#define ABSL_CHECK_STRNE_IMPL(s1, s2) \
ABSL_LOG_INTERNAL_CHECK_STROP(strcmp, !=, false, s1, s2)
#define ABSL_CHECK_STRCASEEQ_IMPL(s1, s2) \
ABSL_LOG_INTERNAL_CHECK_STROP(strcasecmp, ==, true, s1, s2)
#define ABSL_CHECK_STRCASENE_IMPL(s1, s2) \
ABSL_LOG_INTERNAL_CHECK_STROP(strcasecmp, !=, false, s1, s2)
#define ABSL_QCHECK_STREQ_IMPL(s1, s2) \
ABSL_LOG_INTERNAL_QCHECK_STROP(strcmp, ==, true, s1, s2)
#define ABSL_QCHECK_STRNE_IMPL(s1, s2) \
ABSL_LOG_INTERNAL_QCHECK_STROP(strcmp, !=, false, s1, s2)
#define ABSL_QCHECK_STRCASEEQ_IMPL(s1, s2) \
ABSL_LOG_INTERNAL_QCHECK_STROP(strcasecmp, ==, true, s1, s2)
#define ABSL_QCHECK_STRCASENE_IMPL(s1, s2) \
ABSL_LOG_INTERNAL_QCHECK_STROP(strcasecmp, !=, false, s1, s2)
#ifndef NDEBUG
#define ABSL_DCHECK_STREQ_IMPL(s1, s2) ABSL_CHECK_STREQ_IMPL(s1, s2)
#define ABSL_DCHECK_STRCASEEQ_IMPL(s1, s2) ABSL_CHECK_STRCASEEQ_IMPL(s1, s2)
#define ABSL_DCHECK_STRNE_IMPL(s1, s2) ABSL_CHECK_STRNE_IMPL(s1, s2)
#define ABSL_DCHECK_STRCASENE_IMPL(s1, s2) ABSL_CHECK_STRCASENE_IMPL(s1, s2)
#else // ndef NDEBUG
#define ABSL_DCHECK_STREQ_IMPL(s1, s2) ABSL_LOG_INTERNAL_DCHECK_NOP(s1, s2)
#define ABSL_DCHECK_STRCASEEQ_IMPL(s1, s2) ABSL_LOG_INTERNAL_DCHECK_NOP(s1, s2)
#define ABSL_DCHECK_STRNE_IMPL(s1, s2) ABSL_LOG_INTERNAL_DCHECK_NOP(s1, s2)
#define ABSL_DCHECK_STRCASENE_IMPL(s1, s2) ABSL_LOG_INTERNAL_DCHECK_NOP(s1, s2)
#endif // def NDEBUG
#endif // ABSL_LOG_INTERNAL_CHECK_IMPL_H_
// 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.
#ifndef ABSL_LOG_INTERNAL_LOG_IMPL_H_
#define ABSL_LOG_INTERNAL_LOG_IMPL_H_
#include "absl/log/internal/conditions.h"
#include "absl/log/internal/log_message.h"
#include "absl/log/internal/strip.h"
// ABSL_LOG()
#define ABSL_LOG_IMPL(severity) \
ABSL_LOG_INTERNAL_CONDITION##severity(STATELESS, true) \
ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
// ABSL_PLOG()
#define ABSL_PLOG_IMPL(severity) \
ABSL_LOG_INTERNAL_CONDITION##severity(STATELESS, true) \
ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream() \
.WithPerror()
// ABSL_DLOG()
#ifndef NDEBUG
#define ABSL_DLOG_IMPL(severity) \
ABSL_LOG_INTERNAL_CONDITION##severity(STATELESS, true) \
ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
#else
#define ABSL_DLOG_IMPL(severity) \
ABSL_LOG_INTERNAL_CONDITION##severity(STATELESS, false) \
ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
#endif
#define ABSL_LOG_IF_IMPL(severity, condition) \
ABSL_LOG_INTERNAL_CONDITION##severity(STATELESS, condition) \
ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
#define ABSL_PLOG_IF_IMPL(severity, condition) \
ABSL_LOG_INTERNAL_CONDITION##severity(STATELESS, condition) \
ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream() \
.WithPerror()
#ifndef NDEBUG
#define ABSL_DLOG_IF_IMPL(severity, condition) \
ABSL_LOG_INTERNAL_CONDITION##severity(STATELESS, condition) \
ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
#else
#define ABSL_DLOG_IF_IMPL(severity, condition) \
ABSL_LOG_INTERNAL_CONDITION##severity(STATELESS, false && (condition)) \
ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
#endif
// ABSL_LOG_EVERY_N
#define ABSL_LOG_EVERY_N_IMPL(severity, n) \
ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, true)(EveryN, n) \
ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
// ABSL_LOG_FIRST_N
#define ABSL_LOG_FIRST_N_IMPL(severity, n) \
ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, true)(FirstN, n) \
ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
// ABSL_LOG_EVERY_POW_2
#define ABSL_LOG_EVERY_POW_2_IMPL(severity) \
ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, true)(EveryPow2) \
ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
// ABSL_LOG_EVERY_N_SEC
#define ABSL_LOG_EVERY_N_SEC_IMPL(severity, n_seconds) \
ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, true)(EveryNSec, n_seconds) \
ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
#define ABSL_PLOG_EVERY_N_IMPL(severity, n) \
ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, true)(EveryN, n) \
ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream() \
.WithPerror()
#define ABSL_PLOG_FIRST_N_IMPL(severity, n) \
ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, true)(FirstN, n) \
ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream() \
.WithPerror()
#define ABSL_PLOG_EVERY_POW_2_IMPL(severity) \
ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, true)(EveryPow2) \
ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream() \
.WithPerror()
#define ABSL_PLOG_EVERY_N_SEC_IMPL(severity, n_seconds) \
ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, true)(EveryNSec, n_seconds) \
ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream() \
.WithPerror()
#ifndef NDEBUG
#define ABSL_DLOG_EVERY_N_IMPL(severity, n) \
ABSL_LOG_INTERNAL_CONDITION_INFO(STATEFUL, true) \
(EveryN, n) ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
#define ABSL_DLOG_FIRST_N_IMPL(severity, n) \
ABSL_LOG_INTERNAL_CONDITION_INFO(STATEFUL, true) \
(FirstN, n) ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
#define ABSL_DLOG_EVERY_POW_2_IMPL(severity) \
ABSL_LOG_INTERNAL_CONDITION_INFO(STATEFUL, true) \
(EveryPow2) ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
#define ABSL_DLOG_EVERY_N_SEC_IMPL(severity, n_seconds) \
ABSL_LOG_INTERNAL_CONDITION_INFO(STATEFUL, true) \
(EveryNSec, n_seconds) ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
#else // def NDEBUG
#define ABSL_DLOG_EVERY_N_IMPL(severity, n) \
ABSL_LOG_INTERNAL_CONDITION_INFO(STATEFUL, false) \
(EveryN, n) ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
#define ABSL_DLOG_FIRST_N_IMPL(severity, n) \
ABSL_LOG_INTERNAL_CONDITION_INFO(STATEFUL, false) \
(FirstN, n) ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
#define ABSL_DLOG_EVERY_POW_2_IMPL(severity) \
ABSL_LOG_INTERNAL_CONDITION_INFO(STATEFUL, false) \
(EveryPow2) ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
#define ABSL_DLOG_EVERY_N_SEC_IMPL(severity, n_seconds) \
ABSL_LOG_INTERNAL_CONDITION_INFO(STATEFUL, false) \
(EveryNSec, n_seconds) ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
#endif // def NDEBUG
#define ABSL_LOG_IF_EVERY_N_IMPL(severity, condition, n) \
ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, condition)(EveryN, n) \
ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
#define ABSL_LOG_IF_FIRST_N_IMPL(severity, condition, n) \
ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, condition)(FirstN, n) \
ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
#define ABSL_LOG_IF_EVERY_POW_2_IMPL(severity, condition) \
ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, condition)(EveryPow2) \
ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
#define ABSL_LOG_IF_EVERY_N_SEC_IMPL(severity, condition, n_seconds) \
ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, condition)(EveryNSec, \
n_seconds) \
ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
#define ABSL_PLOG_IF_EVERY_N_IMPL(severity, condition, n) \
ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, condition)(EveryN, n) \
ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream() \
.WithPerror()
#define ABSL_PLOG_IF_FIRST_N_IMPL(severity, condition, n) \
ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, condition)(FirstN, n) \
ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream() \
.WithPerror()
#define ABSL_PLOG_IF_EVERY_POW_2_IMPL(severity, condition) \
ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, condition)(EveryPow2) \
ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream() \
.WithPerror()
#define ABSL_PLOG_IF_EVERY_N_SEC_IMPL(severity, condition, n_seconds) \
ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, condition)(EveryNSec, \
n_seconds) \
ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream() \
.WithPerror()
#ifndef NDEBUG
#define ABSL_DLOG_IF_EVERY_N_IMPL(severity, condition, n) \
ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, condition)(EveryN, n) \
ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
#define ABSL_DLOG_IF_FIRST_N_IMPL(severity, condition, n) \
ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, condition)(FirstN, n) \
ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
#define ABSL_DLOG_IF_EVERY_POW_2_IMPL(severity, condition) \
ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, condition)(EveryPow2) \
ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
#define ABSL_DLOG_IF_EVERY_N_SEC_IMPL(severity, condition, n_seconds) \
ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, condition)(EveryNSec, \
n_seconds) \
ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
#else // def NDEBUG
#define ABSL_DLOG_IF_EVERY_N_IMPL(severity, condition, n) \
ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, false && (condition))( \
EveryN, n) ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
#define ABSL_DLOG_IF_FIRST_N_IMPL(severity, condition, n) \
ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, false && (condition))( \
FirstN, n) ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
#define ABSL_DLOG_IF_EVERY_POW_2_IMPL(severity, condition) \
ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, false && (condition))( \
EveryPow2) ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
#define ABSL_DLOG_IF_EVERY_N_SEC_IMPL(severity, condition, n_seconds) \
ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, false && (condition))( \
EveryNSec, n_seconds) \
ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
#endif // def NDEBUG
#endif // ABSL_LOG_INTERNAL_LOG_IMPL_H_
...@@ -187,9 +187,7 @@ ...@@ -187,9 +187,7 @@
#ifndef ABSL_LOG_LOG_H_ #ifndef ABSL_LOG_LOG_H_
#define ABSL_LOG_LOG_H_ #define ABSL_LOG_LOG_H_
#include "absl/log/internal/conditions.h" #include "absl/log/internal/log_impl.h"
#include "absl/log/internal/log_message.h"
#include "absl/log/internal/strip.h"
// LOG() // LOG()
// //
...@@ -198,56 +196,29 @@ ...@@ -198,56 +196,29 @@
// Example: // Example:
// //
// LOG(INFO) << "Found " << num_cookies << " cookies"; // LOG(INFO) << "Found " << num_cookies << " cookies";
#define LOG(severity) \ #define LOG(severity) ABSL_LOG_IMPL(_##severity)
ABSL_LOG_INTERNAL_CONDITION_##severity(STATELESS, true) \
ABSL_LOGGING_INTERNAL_LOG_##severity.InternalStream()
// PLOG() // PLOG()
// //
// `PLOG` behaves like `LOG` except that a description of the current state of // `PLOG` behaves like `LOG` except that a description of the current state of
// `errno` is appended to the streamed message. // `errno` is appended to the streamed message.
#define PLOG(severity) \ #define PLOG(severity) ABSL_PLOG_IMPL(_##severity)
ABSL_LOG_INTERNAL_CONDITION_##severity(STATELESS, true) \
ABSL_LOGGING_INTERNAL_LOG_##severity.InternalStream() \
.WithPerror()
// DLOG() // DLOG()
// //
// `DLOG` behaves like `LOG` in debug mode (i.e. `#ifndef NDEBUG`). Otherwise // `DLOG` behaves like `LOG` in debug mode (i.e. `#ifndef NDEBUG`). Otherwise
// it compiles away and does nothing. Note that `DLOG(FATAL)` does not // it compiles away and does nothing. Note that `DLOG(FATAL)` does not
// terminate the program if `NDEBUG` is defined. // terminate the program if `NDEBUG` is defined.
#ifndef NDEBUG #define DLOG(severity) ABSL_DLOG_IMPL(_##severity)
#define DLOG(severity) \
ABSL_LOG_INTERNAL_CONDITION_##severity(STATELESS, true) \
ABSL_LOGGING_INTERNAL_LOG_##severity.InternalStream()
#else
#define DLOG(severity) \
ABSL_LOG_INTERNAL_CONDITION_##severity(STATELESS, false) \
ABSL_LOGGING_INTERNAL_LOG_##severity.InternalStream()
#endif
// `LOG_IF` and friends add a second argument which specifies a condition. If // `LOG_IF` and friends add a second argument which specifies a condition. If
// the condition is false, nothing is logged. // the condition is false, nothing is logged.
// Example: // Example:
// //
// LOG_IF(INFO, num_cookies > 10) << "Got lots of cookies"; // LOG_IF(INFO, num_cookies > 10) << "Got lots of cookies";
#define LOG_IF(severity, condition) \ #define LOG_IF(severity, condition) ABSL_LOG_IF_IMPL(_##severity, condition)
ABSL_LOG_INTERNAL_CONDITION_##severity(STATELESS, condition) \ #define PLOG_IF(severity, condition) ABSL_PLOG_IF_IMPL(_##severity, condition)
ABSL_LOGGING_INTERNAL_LOG_##severity.InternalStream() #define DLOG_IF(severity, condition) ABSL_DLOG_IF_IMPL(_##severity, condition)
#define PLOG_IF(severity, condition) \
ABSL_LOG_INTERNAL_CONDITION_##severity(STATELESS, condition) \
ABSL_LOGGING_INTERNAL_LOG_##severity.InternalStream() \
.WithPerror()
#ifndef NDEBUG
#define DLOG_IF(severity, condition) \
ABSL_LOG_INTERNAL_CONDITION_##severity(STATELESS, condition) \
ABSL_LOGGING_INTERNAL_LOG_##severity.InternalStream()
#else
#define DLOG_IF(severity, condition) \
ABSL_LOG_INTERNAL_CONDITION_##severity(STATELESS, false && (condition)) \
ABSL_LOGGING_INTERNAL_LOG_##severity.InternalStream()
#endif
// LOG_EVERY_N // LOG_EVERY_N
// //
...@@ -260,27 +231,21 @@ ...@@ -260,27 +231,21 @@
// //
// LOG_EVERY_N(WARNING, 1000) << "Got a packet with a bad CRC (" << COUNTER // LOG_EVERY_N(WARNING, 1000) << "Got a packet with a bad CRC (" << COUNTER
// << " total)"; // << " total)";
#define LOG_EVERY_N(severity, n) \ #define LOG_EVERY_N(severity, n) ABSL_LOG_EVERY_N_IMPL(_##severity, n)
ABSL_LOG_INTERNAL_CONDITION_##severity(STATEFUL, true)(EveryN, n) \
ABSL_LOGGING_INTERNAL_LOG_##severity.InternalStream()
// LOG_FIRST_N // LOG_FIRST_N
// //
// `LOG_FIRST_N` behaves like `LOG_EVERY_N` except that the specified message is // `LOG_FIRST_N` behaves like `LOG_EVERY_N` except that the specified message is
// logged when the counter's value is less than `n`. `LOG_FIRST_N` is // logged when the counter's value is less than `n`. `LOG_FIRST_N` is
// thread-safe. // thread-safe.
#define LOG_FIRST_N(severity, n) \ #define LOG_FIRST_N(severity, n) ABSL_LOG_FIRST_N_IMPL(_##severity, n)
ABSL_LOG_INTERNAL_CONDITION_##severity(STATEFUL, true)(FirstN, n) \
ABSL_LOGGING_INTERNAL_LOG_##severity.InternalStream()
// LOG_EVERY_POW_2 // LOG_EVERY_POW_2
// //
// `LOG_EVERY_POW_2` behaves like `LOG_EVERY_N` except that the specified // `LOG_EVERY_POW_2` behaves like `LOG_EVERY_N` except that the specified
// message is logged when the counter's value is a power of 2. // message is logged when the counter's value is a power of 2.
// `LOG_EVERY_POW_2` is thread-safe. // `LOG_EVERY_POW_2` is thread-safe.
#define LOG_EVERY_POW_2(severity) \ #define LOG_EVERY_POW_2(severity) ABSL_LOG_EVERY_POW_2_IMPL(_##severity)
ABSL_LOG_INTERNAL_CONDITION_##severity(STATEFUL, true)(EveryPow2) \
ABSL_LOGGING_INTERNAL_LOG_##severity.InternalStream()
// LOG_EVERY_N_SEC // LOG_EVERY_N_SEC
// //
...@@ -291,64 +256,20 @@ ...@@ -291,64 +256,20 @@
// Example: // Example:
// //
// LOG_EVERY_N_SEC(INFO, 2.5) << "Got " << COUNTER << " cookies so far"; // LOG_EVERY_N_SEC(INFO, 2.5) << "Got " << COUNTER << " cookies so far";
#define LOG_EVERY_N_SEC(severity, n_seconds) \ #define LOG_EVERY_N_SEC(severity, n_seconds) \
ABSL_LOG_INTERNAL_CONDITION_##severity(STATEFUL, true)(EveryNSec, n_seconds) \ ABSL_LOG_EVERY_N_SEC_IMPL(_##severity, n_seconds)
ABSL_LOGGING_INTERNAL_LOG_##severity.InternalStream()
#define PLOG_EVERY_N(severity, n) \
ABSL_LOG_INTERNAL_CONDITION_##severity(STATEFUL, true)(EveryN, n) \
ABSL_LOGGING_INTERNAL_LOG_##severity.InternalStream() \
.WithPerror()
#define PLOG_FIRST_N(severity, n) \
ABSL_LOG_INTERNAL_CONDITION_##severity(STATEFUL, true)(FirstN, n) \
ABSL_LOGGING_INTERNAL_LOG_##severity.InternalStream() \
.WithPerror()
#define PLOG_EVERY_POW_2(severity) \
ABSL_LOG_INTERNAL_CONDITION_##severity(STATEFUL, true)(EveryPow2) \
ABSL_LOGGING_INTERNAL_LOG_##severity.InternalStream() \
.WithPerror()
#define PLOG_EVERY_N_SEC(severity, n_seconds) \
ABSL_LOG_INTERNAL_CONDITION_##severity(STATEFUL, true)(EveryNSec, n_seconds) \
ABSL_LOGGING_INTERNAL_LOG_##severity.InternalStream() \
.WithPerror()
#ifndef NDEBUG
#define DLOG_EVERY_N(severity, n) \
ABSL_LOG_INTERNAL_CONDITION_INFO(STATEFUL, true) \
(EveryN, n) ABSL_LOGGING_INTERNAL_LOG_##severity.InternalStream()
#define DLOG_FIRST_N(severity, n) \
ABSL_LOG_INTERNAL_CONDITION_INFO(STATEFUL, true) \
(FirstN, n) ABSL_LOGGING_INTERNAL_LOG_##severity.InternalStream()
#define DLOG_EVERY_POW_2(severity) \ #define PLOG_EVERY_N(severity, n) ABSL_PLOG_EVERY_N_IMPL(_##severity, n)
ABSL_LOG_INTERNAL_CONDITION_INFO(STATEFUL, true) \ #define PLOG_FIRST_N(severity, n) ABSL_PLOG_FIRST_N_IMPL(_##severity, n)
(EveryPow2) ABSL_LOGGING_INTERNAL_LOG_##severity.InternalStream() #define PLOG_EVERY_POW_2(severity) ABSL_PLOG_EVERY_POW_2_IMPL(_##severity)
#define PLOG_EVERY_N_SEC(severity, n_seconds) \
ABSL_PLOG_EVERY_N_SEC_IMPL(_##severity, n_seconds)
#define DLOG_EVERY_N_SEC(severity, n_seconds) \ #define DLOG_EVERY_N(severity, n) ABSL_DLOG_EVERY_N_IMPL(_##severity, n)
ABSL_LOG_INTERNAL_CONDITION_INFO(STATEFUL, true) \ #define DLOG_FIRST_N(severity, n) ABSL_DLOG_FIRST_N_IMPL(_##severity, n)
(EveryNSec, n_seconds) ABSL_LOGGING_INTERNAL_LOG_##severity.InternalStream() #define DLOG_EVERY_POW_2(severity) ABSL_DLOG_EVERY_POW_2_IMPL(_##severity)
#define DLOG_EVERY_N_SEC(severity, n_seconds) \
#else // def NDEBUG ABSL_DLOG_EVERY_N_SEC_IMPL(_##severity, n_seconds)
#define DLOG_EVERY_N(severity, n) \
ABSL_LOG_INTERNAL_CONDITION_INFO(STATEFUL, false) \
(EveryN, n) ABSL_LOGGING_INTERNAL_LOG_##severity.InternalStream()
#define DLOG_FIRST_N(severity, n) \
ABSL_LOG_INTERNAL_CONDITION_INFO(STATEFUL, false) \
(FirstN, n) ABSL_LOGGING_INTERNAL_LOG_##severity.InternalStream()
#define DLOG_EVERY_POW_2(severity) \
ABSL_LOG_INTERNAL_CONDITION_INFO(STATEFUL, false) \
(EveryPow2) ABSL_LOGGING_INTERNAL_LOG_##severity.InternalStream()
#define DLOG_EVERY_N_SEC(severity, n_seconds) \
ABSL_LOG_INTERNAL_CONDITION_INFO(STATEFUL, false) \
(EveryNSec, n_seconds) ABSL_LOGGING_INTERNAL_LOG_##severity.InternalStream()
#endif // def NDEBUG
// `LOG_IF_EVERY_N` and friends behave as the corresponding `LOG_EVERY_N` // `LOG_IF_EVERY_N` and friends behave as the corresponding `LOG_EVERY_N`
// but neither increment a counter nor log a message if condition is false (as // but neither increment a counter nor log a message if condition is false (as
...@@ -357,79 +278,31 @@ ...@@ -357,79 +278,31 @@
// //
// LOG_IF_EVERY_N(INFO, (size > 1024), 10) << "Got the " << COUNTER // LOG_IF_EVERY_N(INFO, (size > 1024), 10) << "Got the " << COUNTER
// << "th big cookie"; // << "th big cookie";
#define LOG_IF_EVERY_N(severity, condition, n) \ #define LOG_IF_EVERY_N(severity, condition, n) \
ABSL_LOG_INTERNAL_CONDITION_##severity(STATEFUL, condition)(EveryN, n) \ ABSL_LOG_IF_EVERY_N_IMPL(_##severity, condition, n)
ABSL_LOGGING_INTERNAL_LOG_##severity.InternalStream() #define LOG_IF_FIRST_N(severity, condition, n) \
ABSL_LOG_IF_FIRST_N_IMPL(_##severity, condition, n)
#define LOG_IF_FIRST_N(severity, condition, n) \ #define LOG_IF_EVERY_POW_2(severity, condition) \
ABSL_LOG_INTERNAL_CONDITION_##severity(STATEFUL, condition)(FirstN, n) \ ABSL_LOG_IF_EVERY_POW_2_IMPL(_##severity, condition)
ABSL_LOGGING_INTERNAL_LOG_##severity.InternalStream() #define LOG_IF_EVERY_N_SEC(severity, condition, n_seconds) \
ABSL_LOG_IF_EVERY_N_SEC_IMPL(_##severity, condition, n_seconds)
#define LOG_IF_EVERY_POW_2(severity, condition) \
ABSL_LOG_INTERNAL_CONDITION_##severity(STATEFUL, condition)(EveryPow2) \ #define PLOG_IF_EVERY_N(severity, condition, n) \
ABSL_LOGGING_INTERNAL_LOG_##severity.InternalStream() ABSL_PLOG_IF_EVERY_N_IMPL(_##severity, condition, n)
#define PLOG_IF_FIRST_N(severity, condition, n) \
#define LOG_IF_EVERY_N_SEC(severity, condition, n_seconds) \ ABSL_PLOG_IF_FIRST_N_IMPL(_##severity, condition, n)
ABSL_LOG_INTERNAL_CONDITION_##severity(STATEFUL, condition)(EveryNSec, \ #define PLOG_IF_EVERY_POW_2(severity, condition) \
n_seconds) \ ABSL_PLOG_IF_EVERY_POW_2_IMPL(_##severity, condition)
ABSL_LOGGING_INTERNAL_LOG_##severity.InternalStream() #define PLOG_IF_EVERY_N_SEC(severity, condition, n_seconds) \
ABSL_PLOG_IF_EVERY_N_SEC_IMPL(_##severity, condition, n_seconds)
#define PLOG_IF_EVERY_N(severity, condition, n) \
ABSL_LOG_INTERNAL_CONDITION_##severity(STATEFUL, condition)(EveryN, n) \ #define DLOG_IF_EVERY_N(severity, condition, n) \
ABSL_LOGGING_INTERNAL_LOG_##severity.InternalStream() \ ABSL_DLOG_IF_EVERY_N_IMPL(_##severity, condition, n)
.WithPerror() #define DLOG_IF_FIRST_N(severity, condition, n) \
ABSL_DLOG_IF_FIRST_N_IMPL(_##severity, condition, n)
#define PLOG_IF_FIRST_N(severity, condition, n) \ #define DLOG_IF_EVERY_POW_2(severity, condition) \
ABSL_LOG_INTERNAL_CONDITION_##severity(STATEFUL, condition)(FirstN, n) \ ABSL_DLOG_IF_EVERY_POW_2_IMPL(_##severity, condition)
ABSL_LOGGING_INTERNAL_LOG_##severity.InternalStream() \ #define DLOG_IF_EVERY_N_SEC(severity, condition, n_seconds) \
.WithPerror() ABSL_DLOG_IF_EVERY_N_SEC_IMPL(_##severity, condition, n_seconds)
#define PLOG_IF_EVERY_POW_2(severity, condition) \
ABSL_LOG_INTERNAL_CONDITION_##severity(STATEFUL, condition)(EveryPow2) \
ABSL_LOGGING_INTERNAL_LOG_##severity.InternalStream() \
.WithPerror()
#define PLOG_IF_EVERY_N_SEC(severity, condition, n_seconds) \
ABSL_LOG_INTERNAL_CONDITION_##severity(STATEFUL, condition)(EveryNSec, \
n_seconds) \
ABSL_LOGGING_INTERNAL_LOG_##severity.InternalStream() \
.WithPerror()
#ifndef NDEBUG
#define DLOG_IF_EVERY_N(severity, condition, n) \
ABSL_LOG_INTERNAL_CONDITION_##severity(STATEFUL, condition)(EveryN, n) \
ABSL_LOGGING_INTERNAL_LOG_##severity.InternalStream()
#define DLOG_IF_FIRST_N(severity, condition, n) \
ABSL_LOG_INTERNAL_CONDITION_##severity(STATEFUL, condition)(FirstN, n) \
ABSL_LOGGING_INTERNAL_LOG_##severity.InternalStream()
#define DLOG_IF_EVERY_POW_2(severity, condition) \
ABSL_LOG_INTERNAL_CONDITION_##severity(STATEFUL, condition)(EveryPow2) \
ABSL_LOGGING_INTERNAL_LOG_##severity.InternalStream()
#define DLOG_IF_EVERY_N_SEC(severity, condition, n_seconds) \
ABSL_LOG_INTERNAL_CONDITION_##severity(STATEFUL, condition)(EveryNSec, \
n_seconds) \
ABSL_LOGGING_INTERNAL_LOG_##severity.InternalStream()
#else // def NDEBUG
#define DLOG_IF_EVERY_N(severity, condition, n) \
ABSL_LOG_INTERNAL_CONDITION_##severity(STATEFUL, false && (condition))( \
EveryN, n) ABSL_LOGGING_INTERNAL_LOG_##severity.InternalStream()
#define DLOG_IF_FIRST_N(severity, condition, n) \
ABSL_LOG_INTERNAL_CONDITION_##severity(STATEFUL, false && (condition))( \
FirstN, n) ABSL_LOGGING_INTERNAL_LOG_##severity.InternalStream()
#define DLOG_IF_EVERY_POW_2(severity, condition) \
ABSL_LOG_INTERNAL_CONDITION_##severity(STATEFUL, false && (condition))( \
EveryPow2) ABSL_LOGGING_INTERNAL_LOG_##severity.InternalStream()
#define DLOG_IF_EVERY_N_SEC(severity, condition, n_seconds) \
ABSL_LOG_INTERNAL_CONDITION_##severity(STATEFUL, false && (condition))( \
EveryNSec, n_seconds) \
ABSL_LOGGING_INTERNAL_LOG_##severity.InternalStream()
#endif // def NDEBUG
#endif // ABSL_LOG_LOG_H_ #endif // ABSL_LOG_LOG_H_
...@@ -139,6 +139,22 @@ TEST(LogHygieneTest, WorksWithINFODefined) { ...@@ -139,6 +139,22 @@ TEST(LogHygieneTest, WorksWithINFODefined) {
#undef INFO #undef INFO
#define _INFO Bogus
TEST(LogHygieneTest, WorksWithUnderscoreINFODefined) {
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
EXPECT_CALL(test_sink, Log(absl::LogSeverity::kInfo, _, "Hello world"))
.Times(2 + (IsOptimized ? 2 : 0));
test_sink.StartCapturingLogs();
LOG(INFO) << "Hello world";
LOG_IF(INFO, true) << "Hello world";
DLOG(INFO) << "Hello world";
DLOG_IF(INFO, true) << "Hello world";
}
#undef _INFO
TEST(LogHygieneTest, ExpressionEvaluationInLEVELSeverity) { TEST(LogHygieneTest, ExpressionEvaluationInLEVELSeverity) {
auto i = static_cast<int>(absl::LogSeverity::kInfo); auto i = static_cast<int>(absl::LogSeverity::kInfo);
LOG(LEVEL(++i)) << "hello world"; // NOLINT LOG(LEVEL(++i)) << "hello world"; // NOLINT
......
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