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(
copts = ABSL_DEFAULT_COPTS,
linkopts = ABSL_DEFAULT_LINKOPTS,
deps = [
"//absl/base:core_headers",
"//absl/log/internal:check_impl",
"//absl/log/internal:check_op",
"//absl/log/internal:conditions",
"//absl/log/internal:log_message",
......@@ -114,9 +114,7 @@ cc_library(
copts = ABSL_DEFAULT_COPTS,
linkopts = ABSL_DEFAULT_LINKOPTS,
deps = [
"//absl/log/internal:conditions",
"//absl/log/internal:log_message",
"//absl/log/internal:strip",
"//absl/log/internal:log_impl",
],
)
......
......@@ -17,6 +17,24 @@
# Internal targets
absl_cc_library(
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
SRCS
"internal/check_op.cc"
......@@ -128,6 +146,22 @@ absl_cc_library(
absl_cc_library(
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
SRCS
"internal/proto.cc"
......@@ -366,6 +400,7 @@ absl_cc_library(
LINKOPTS
${ABSL_DEFAULT_LINKOPTS}
DEPS
absl::log_internal_check_impl
absl::core_headers
absl::log_internal_check_op
absl::log_internal_conditions
......@@ -467,9 +502,7 @@ absl_cc_library(
LINKOPTS
${ABSL_DEFAULT_LINKOPTS}
DEPS
absl::log_internal_conditions
absl::log_internal_message
absl::log_internal_strip
absl::log_internal_log_impl
PUBLIC
)
......
......@@ -34,7 +34,7 @@
#ifndef 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/conditions.h" // IWYU pragma: export
#include "absl/log/internal/log_message.h" // IWYU pragma: export
......@@ -54,10 +54,7 @@
// Might produce a message like:
//
// Check failed: !cheese.empty() Out of Cheese
#define CHECK(condition) \
ABSL_LOG_INTERNAL_CONDITION_FATAL(STATELESS, \
ABSL_PREDICT_FALSE(!(condition))) \
ABSL_LOG_INTERNAL_CHECK(#condition).InternalStream()
#define CHECK(condition) ABSL_CHECK_IMPL(condition)
// QCHECK()
//
......@@ -65,10 +62,7 @@
// not run registered error handlers (as `QFATAL`). It is useful when the
// problem is definitely unrelated to program flow, e.g. when validating user
// input.
#define QCHECK(condition) \
ABSL_LOG_INTERNAL_CONDITION_QFATAL(STATELESS, \
ABSL_PREDICT_FALSE(!(condition))) \
ABSL_LOG_INTERNAL_QCHECK(#condition).InternalStream()
#define QCHECK(condition) ABSL_QCHECK_IMPL(condition)
// PCHECK()
//
......@@ -83,7 +77,7 @@
// Might produce a message like:
//
// 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()
//
......@@ -91,11 +85,7 @@
// `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
// evaluate the condition.
#ifndef NDEBUG
#define DCHECK(condition) CHECK(condition)
#else
#define DCHECK(condition) CHECK(true || (condition))
#endif
#define DCHECK(condition) ABSL_DCHECK_IMPL(condition)
// `CHECK_EQ` and friends are syntactic sugar for `CHECK(x == y)` that
// automatically output the expression being tested and the evaluated values on
......@@ -123,43 +113,24 @@
//
// WARNING: Passing `NULL` as an argument to `CHECK_EQ` and similar macros does
// not compile. Use `nullptr` instead.
#define CHECK_EQ(val1, val2) \
ABSL_LOG_INTERNAL_CHECK_OP(Check_EQ, ==, val1, val2)
#define CHECK_NE(val1, val2) \
ABSL_LOG_INTERNAL_CHECK_OP(Check_NE, !=, val1, val2)
#define CHECK_LE(val1, val2) \
ABSL_LOG_INTERNAL_CHECK_OP(Check_LE, <=, val1, val2)
#define CHECK_LT(val1, val2) ABSL_LOG_INTERNAL_CHECK_OP(Check_LT, <, val1, val2)
#define CHECK_GE(val1, val2) \
ABSL_LOG_INTERNAL_CHECK_OP(Check_GE, >=, val1, val2)
#define CHECK_GT(val1, val2) ABSL_LOG_INTERNAL_CHECK_OP(Check_GT, >, val1, val2)
#define QCHECK_EQ(val1, val2) \
ABSL_LOG_INTERNAL_QCHECK_OP(Check_EQ, ==, val1, val2)
#define QCHECK_NE(val1, val2) \
ABSL_LOG_INTERNAL_QCHECK_OP(Check_NE, !=, val1, val2)
#define QCHECK_LE(val1, val2) \
ABSL_LOG_INTERNAL_QCHECK_OP(Check_LE, <=, val1, val2)
#define QCHECK_LT(val1, val2) \
ABSL_LOG_INTERNAL_QCHECK_OP(Check_LT, <, 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
#define CHECK_EQ(val1, val2) ABSL_CHECK_EQ_IMPL(val1, val2)
#define CHECK_NE(val1, val2) ABSL_CHECK_NE_IMPL(val1, val2)
#define CHECK_LE(val1, val2) ABSL_CHECK_LE_IMPL(val1, val2)
#define CHECK_LT(val1, val2) ABSL_CHECK_LT_IMPL(val1, val2)
#define CHECK_GE(val1, val2) ABSL_CHECK_GE_IMPL(val1, val2)
#define CHECK_GT(val1, val2) ABSL_CHECK_GT_IMPL(val1, val2)
#define QCHECK_EQ(val1, val2) ABSL_QCHECK_EQ_IMPL(val1, val2)
#define QCHECK_NE(val1, val2) ABSL_QCHECK_NE_IMPL(val1, val2)
#define QCHECK_LE(val1, val2) ABSL_QCHECK_LE_IMPL(val1, val2)
#define QCHECK_LT(val1, val2) ABSL_QCHECK_LT_IMPL(val1, val2)
#define QCHECK_GE(val1, val2) ABSL_QCHECK_GE_IMPL(val1, val2)
#define QCHECK_GT(val1, val2) ABSL_QCHECK_GT_IMPL(val1, val2)
#define DCHECK_EQ(val1, val2) ABSL_DCHECK_EQ_IMPL(val1, val2)
#define DCHECK_NE(val1, val2) ABSL_DCHECK_NE_IMPL(val1, val2)
#define DCHECK_LE(val1, val2) ABSL_DCHECK_LE_IMPL(val1, val2)
#define DCHECK_LT(val1, val2) ABSL_DCHECK_LT_IMPL(val1, val2)
#define DCHECK_GE(val1, val2) ABSL_DCHECK_GE_IMPL(val1, val2)
#define DCHECK_GT(val1, val2) ABSL_DCHECK_GT_IMPL(val1, val2)
// `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
......@@ -175,13 +146,9 @@
// Might produce a message like:
//
// Check failed: FunctionReturnsStatus(x, y, z) is OK (ABORTED: timeout) oops!
#define CHECK_OK(status) ABSL_LOG_INTERNAL_CHECK_OK(status)
#define QCHECK_OK(status) ABSL_LOG_INTERNAL_QCHECK_OK(status)
#ifndef NDEBUG
#define DCHECK_OK(status) ABSL_LOG_INTERNAL_CHECK_OK(status)
#else
#define DCHECK_OK(status) ABSL_LOG_INTERNAL_DCHECK_NOP(status, nullptr)
#endif
#define CHECK_OK(status) ABSL_CHECK_OK_IMPL(status)
#define QCHECK_OK(status) ABSL_QCHECK_OK_IMPL(status)
#define DCHECK_OK(status) ABSL_DCHECK_OK_IMPL(status)
// `CHECK_STREQ` and friends provide `CHECK_EQ` functionality for C strings,
// i.e., nul-terminated char arrays. The `CASE` versions are case-insensitive.
......@@ -196,32 +163,17 @@
// Example:
//
// CHECK_STREQ(Foo().c_str(), Bar().c_str());
#define CHECK_STREQ(s1, s2) \
ABSL_LOG_INTERNAL_CHECK_STROP(strcmp, ==, true, s1, s2)
#define CHECK_STRNE(s1, s2) \
ABSL_LOG_INTERNAL_CHECK_STROP(strcmp, !=, false, s1, s2)
#define CHECK_STRCASEEQ(s1, s2) \
ABSL_LOG_INTERNAL_CHECK_STROP(strcasecmp, ==, true, s1, s2)
#define CHECK_STRCASENE(s1, s2) \
ABSL_LOG_INTERNAL_CHECK_STROP(strcasecmp, !=, false, s1, s2)
#define QCHECK_STREQ(s1, s2) \
ABSL_LOG_INTERNAL_QCHECK_STROP(strcmp, ==, true, s1, s2)
#define QCHECK_STRNE(s1, s2) \
ABSL_LOG_INTERNAL_QCHECK_STROP(strcmp, !=, false, 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
#define CHECK_STREQ(s1, s2) ABSL_CHECK_STREQ_IMPL(s1, s2)
#define CHECK_STRNE(s1, s2) ABSL_CHECK_STRNE_IMPL(s1, s2)
#define CHECK_STRCASEEQ(s1, s2) ABSL_CHECK_STRCASEEQ_IMPL(s1, s2)
#define CHECK_STRCASENE(s1, s2) ABSL_CHECK_STRCASENE_IMPL(s1, s2)
#define QCHECK_STREQ(s1, s2) ABSL_QCHECK_STREQ_IMPL(s1, s2)
#define QCHECK_STRNE(s1, s2) ABSL_QCHECK_STRNE_IMPL(s1, s2)
#define QCHECK_STRCASEEQ(s1, s2) ABSL_QCHECK_STRCASEEQ_IMPL(s1, s2)
#define QCHECK_STRCASENE(s1, s2) ABSL_QCHECK_STRCASENE_IMPL(s1, s2)
#define DCHECK_STREQ(s1, s2) ABSL_DCHECK_STREQ_IMPL(s1, s2)
#define DCHECK_STRNE(s1, s2) ABSL_DCHECK_STRNE_IMPL(s1, s2)
#define DCHECK_STRCASEEQ(s1, s2) ABSL_DCHECK_STRCASEEQ_IMPL(s1, s2)
#define DCHECK_STRCASENE(s1, s2) ABSL_DCHECK_STRCASENE_IMPL(s1, s2)
#endif // ABSL_LOG_CHECK_H_
......@@ -28,6 +28,20 @@ package(default_visibility = [
licenses(["notice"])
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",
srcs = ["check_op.cc"],
hdrs = ["check_op.h"],
......@@ -124,6 +138,18 @@ 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",
srcs = ["log_message.cc"],
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_
......@@ -139,6 +139,22 @@ TEST(LogHygieneTest, WorksWithINFODefined) {
#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) {
auto i = static_cast<int>(absl::LogSeverity::kInfo);
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