chromium/third_party/openscreen/src/util/osp_logging.h

// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef UTIL_OSP_LOGGING_H_
#define UTIL_OSP_LOGGING_H_

#include <sstream>
#include <string_view>
#include <utility>

#include "platform/api/logging.h"

namespace openscreen::internal {

// The stream-based logging macros below are adapted from Chromium's
// base/logging.h.
class LogMessage {};

// Used by the OSP_LAZY_STREAM macro to return void after evaluating an ostream
// chain expression.
class Voidify {};

}  // namespace openscreen::internal

#define OSP_LAZY_STREAM(condition, stream)
#define OSP_LOG_IS_ON(level_enum)
#define OSP_LOG_STREAM(level_enum)

#define OSP_VLOG
#define OSP_LOG_INFO
#define OSP_LOG_WARN
#define OSP_LOG_ERROR
#define OSP_LOG_FATAL

#define OSP_VLOG_IF(condition)
#define OSP_LOG_IF(level, condition)

#define OSP_CHECK(condition)

#define OSP_CHECK_EQ(a, b)
#define OSP_CHECK_NE(a, b)
#define OSP_CHECK_LT(a, b)
#define OSP_CHECK_LE(a, b)
#define OSP_CHECK_GT(a, b)
#define OSP_CHECK_GE(a, b)

#if defined(_DEBUG) || defined(DCHECK_ALWAYS_ON)
#define OSP_DCHECK_IS_ON()
#define OSP_DCHECK(condition)
#define OSP_DCHECK_EQ(a, b)
#define OSP_DCHECK_NE(a, b)
#define OSP_DCHECK_LT(a, b)
#define OSP_DCHECK_LE(a, b)
#define OSP_DCHECK_GT(a, b)
#define OSP_DCHECK_GE(a, b)
#else
#define OSP_DCHECK_IS_ON
// When DCHECKs are off, nothing will be logged. Use that fact to make
// references to the |condition| expression (or |a| and |b|) so the compiler
// won't emit unused variable warnings/errors when DCHECKs are turned off.
#define OSP_EAT_STREAM
#define OSP_DCHECK
#define OSP_DCHECK_EQ
#define OSP_DCHECK_NE
#define OSP_DCHECK_LT
#define OSP_DCHECK_LE
#define OSP_DCHECK_GT
#define OSP_DCHECK_GE
#endif

#define OSP_DVLOG
#define OSP_DLOG_INFO
#define OSP_DLOG_WARN
#define OSP_DLOG_ERROR
#define OSP_DLOG_FATAL
#define OSP_DVLOG_IF(condition)
#define OSP_DLOG_IF(level, condition)

// Log when unimplemented code points are reached: If verbose logging is turned
// on, log always. Otherwise, just attempt to log once.
#define OSP_UNIMPLEMENTED()

// Since Break() is annotated as noreturn, this will properly signal to the
// compiler that this code is truly not reached (and thus doesn't need a return
// statement for non-void returning functions/methods).
#define OSP_NOTREACHED()

#endif  // UTIL_OSP_LOGGING_H_