Chromium Embedded Framework (CEF)  130.1.2+g48f3ef6+chromium-130.0.6723.44
cef_logging.h File Reference

A bunch of macros for logging. More...

#include <cassert>
#include <cstring>
#include <sstream>
#include <string>
#include "include/base/cef_build.h"
#include "include/internal/cef_logging_internal.h"

Namespaces

 cef
 

Macros

#define COMPACT_GOOGLE_LOG_EX_INFO(ClassName, ...)
 
#define COMPACT_GOOGLE_LOG_EX_WARNING(ClassName, ...)
 
#define COMPACT_GOOGLE_LOG_EX_ERROR(ClassName, ...)
 
#define COMPACT_GOOGLE_LOG_EX_FATAL(ClassName, ...)
 
#define COMPACT_GOOGLE_LOG_EX_DFATAL(ClassName, ...)
 
#define COMPACT_GOOGLE_LOG_INFO   COMPACT_GOOGLE_LOG_EX_INFO(LogMessage)
 
#define COMPACT_GOOGLE_LOG_WARNING   COMPACT_GOOGLE_LOG_EX_WARNING(LogMessage)
 
#define COMPACT_GOOGLE_LOG_ERROR   COMPACT_GOOGLE_LOG_EX_ERROR(LogMessage)
 
#define COMPACT_GOOGLE_LOG_FATAL   COMPACT_GOOGLE_LOG_EX_FATAL(LogMessage)
 
#define COMPACT_GOOGLE_LOG_DFATAL   COMPACT_GOOGLE_LOG_EX_DFATAL(LogMessage)
 
#define ERROR   0
 
#define COMPACT_GOOGLE_LOG_EX_0(ClassName, ...)    COMPACT_GOOGLE_LOG_EX_ERROR(ClassName, ##__VA_ARGS__)
 
#define COMPACT_GOOGLE_LOG_0   COMPACT_GOOGLE_LOG_ERROR
 
#define LOG_IS_ON(severity)    ((::cef::logging::LOG_##severity) >= ::cef::logging::GetMinLogLevel())
 
#define VLOG_IS_ON(verboselevel)    ((verboselevel) <= ::cef::logging::GetVlogLevel(__FILE__))
 
#define LAZY_STREAM(stream, condition)    !(condition) ? (void)0 : ::cef::logging::LogMessageVoidify() & (stream)
 
#define LOG_STREAM(severity)   COMPACT_GOOGLE_LOG_##severity.stream()
 
#define LOG(severity)   LAZY_STREAM(LOG_STREAM(severity), LOG_IS_ON(severity))
 
#define LOG_IF(severity, condition)    LAZY_STREAM(LOG_STREAM(severity), LOG_IS_ON(severity) && (condition))
 
#define SYSLOG(severity)   LOG(severity)
 
#define SYSLOG_IF(severity, condition)   LOG_IF(severity, condition)
 
#define VLOG_STREAM(verbose_level)    cef::logging::LogMessage(__FILE__, __LINE__, -verbose_level).stream()
 
#define VLOG(verbose_level)    LAZY_STREAM(VLOG_STREAM(verbose_level), VLOG_IS_ON(verbose_level))
 
#define VLOG_IF(verbose_level, condition)
 
#define VPLOG_STREAM(verbose_level)
 
#define VPLOG(verbose_level)    LAZY_STREAM(VPLOG_STREAM(verbose_level), VLOG_IS_ON(verbose_level))
 
#define VPLOG_IF(verbose_level, condition)
 
#define LOG_ASSERT(condition)    LOG_IF(FATAL, !(condition)) << "Assert failed: " #condition ". "
 
#define SYSLOG_ASSERT(condition)    SYSLOG_IF(FATAL, !(condition)) << "Assert failed: " #condition ". "
 
#define PLOG_STREAM(severity)
 
#define PLOG(severity)   LAZY_STREAM(PLOG_STREAM(severity), LOG_IS_ON(severity))
 
#define PLOG_IF(severity, condition)    LAZY_STREAM(PLOG_STREAM(severity), LOG_IS_ON(severity) && (condition))
 
#define EAT_STREAM_PARAMETERS    true ? (void)0 : ::cef::logging::LogMessageVoidify() & LOG_STREAM(FATAL)
 
#define CHECK(condition)
 
#define PCHECK(condition)
 
#define CHECK_OP(name, op, val1, val2)
 
#define DEFINE_CHECK_OP_IMPL(name, op)
 
#define CHECK_EQ(val1, val2)   CHECK_OP(EQ, ==, val1, val2)
 
#define CHECK_NE(val1, val2)   CHECK_OP(NE, !=, val1, val2)
 
#define CHECK_LE(val1, val2)   CHECK_OP(LE, <=, val1, val2)
 
#define CHECK_LT(val1, val2)   CHECK_OP(LT, <, val1, val2)
 
#define CHECK_GE(val1, val2)   CHECK_OP(GE, >=, val1, val2)
 
#define CHECK_GT(val1, val2)   CHECK_OP(GT, >, val1, val2)
 
#define ENABLE_DLOG   1
 
#define DCHECK_IS_ON()   1
 
#define DLOG_IS_ON(severity)   LOG_IS_ON(severity)
 
#define DLOG_IF(severity, condition)   LOG_IF(severity, condition)
 
#define DLOG_ASSERT(condition)   LOG_ASSERT(condition)
 
#define DPLOG_IF(severity, condition)   PLOG_IF(severity, condition)
 
#define DVLOG_IF(verboselevel, condition)   VLOG_IF(verboselevel, condition)
 
#define DVPLOG_IF(verboselevel, condition)   VPLOG_IF(verboselevel, condition)
 
#define DLOG(severity)   LAZY_STREAM(LOG_STREAM(severity), DLOG_IS_ON(severity))
 
#define DPLOG(severity)   LAZY_STREAM(PLOG_STREAM(severity), DLOG_IS_ON(severity))
 
#define DVLOG(verboselevel)   DVLOG_IF(verboselevel, VLOG_IS_ON(verboselevel))
 
#define DVPLOG(verboselevel)   DVPLOG_IF(verboselevel, VLOG_IS_ON(verboselevel))
 
#define COMPACT_GOOGLE_LOG_EX_DCHECK(ClassName, ...)    COMPACT_GOOGLE_LOG_EX_FATAL(ClassName, ##__VA_ARGS__)
 
#define COMPACT_GOOGLE_LOG_DCHECK   COMPACT_GOOGLE_LOG_FATAL
 
#define DCHECK(condition)
 
#define DPCHECK(condition)
 
#define DCHECK_OP(name, op, val1, val2)
 
#define DCHECK_EQ(val1, val2)   DCHECK_OP(EQ, ==, val1, val2)
 
#define DCHECK_NE(val1, val2)   DCHECK_OP(NE, !=, val1, val2)
 
#define DCHECK_LE(val1, val2)   DCHECK_OP(LE, <=, val1, val2)
 
#define DCHECK_LT(val1, val2)   DCHECK_OP(LT, <, val1, val2)
 
#define DCHECK_GE(val1, val2)   DCHECK_OP(GE, >=, val1, val2)
 
#define DCHECK_GT(val1, val2)   DCHECK_OP(GT, >, val1, val2)
 
#define NOTREACHED()   DCHECK(false)
 
#define assert(x)   DLOG_ASSERT(x)
 
#define NOTIMPLEMENTED_POLICY   4
 
#define NOTIMPLEMENTED_MSG   "NOT IMPLEMENTED"
 
#define NOTIMPLEMENTED()   LOG(ERROR) << NOTIMPLEMENTED_MSG
 

Functions

std::ostream & operator<< (std::ostream &out, const wchar_t *wstr)
 
std::ostream & operator<< (std::ostream &out, const std::wstring &wstr)
 

Detailed Description

A bunch of macros for logging.

NOTE: The contents of this file are only available to applications that link against the libcef_dll_wrapper target.

WARNING: Logging macros should not be used in the main/browser process before calling CefInitialize or in sub-processes before calling CefExecuteProcess.

INSTRUCTIONS:

The way to log things is to stream things to LOG(). E.g.,

  LOG(INFO) << "Found " << num_cookies << " cookies";

You can also do conditional logging:

  LOG_IF(INFO, num_cookies > 10) << "Got lots of cookies";

The CHECK(condition) macro is active in both debug and release builds and effectively performs a LOG(FATAL) which terminates the process and generates a crashdump unless a debugger is attached.

There are also "debug mode" logging macros like the ones above:

  DLOG(INFO) << "Found cookies";

  DLOG_IF(INFO, num_cookies > 10) << "Got lots of cookies";

All "debug mode" logging is compiled away to nothing for non-debug mode compiles. LOG_IF and development flags also work well together because the code can be compiled away sometimes.

We also have

  LOG_ASSERT(assertion);
  DLOG_ASSERT(assertion);

which is syntactic sugar for "{,D}LOG_IF(FATAL, assert fails) << assertion;"

There are "verbose level" logging macros. They look like

  VLOG(1) << "I'm printed when you run the program with --v=1 or more";
  VLOG(2) << "I'm printed when you run the program with --v=2 or more";

These always log at the INFO log level (when they log at all). The verbose logging can also be turned on module-by-module. For instance,

   --vmodule=profile=2,icon_loader=1,browser_*=3,*‍/chromeos/*=4 --v=0

will cause:

  1. VLOG(2) and lower messages to be printed from profile.{h,cc}
  2. VLOG(1) and lower messages to be printed from icon_loader.{h,cc}
  3. VLOG(3) and lower messages to be printed from files prefixed with "browser"
  4. VLOG(4) and lower messages to be printed from files under a "chromeos" directory.
  5. VLOG(0) and lower messages to be printed from elsewhere

The wildcarding functionality shown by (c) supports both '*' (match 0 or more characters) and '?' (match any single character) wildcards. Any pattern containing a forward or backward slash will be tested against the whole pathname and not just the module. E.g., "*&zwj;/foo/bar/*=2" would change the logging level for all code in source files under a "foo/bar" directory.

There's also VLOG_IS_ON(n) "verbose level" condition macro. To be used as

  if (VLOG_IS_ON(2)) {
    // do some logging preparation and logging
    // that can't be accomplished with just VLOG(2) << ...;
  }

There is also a VLOG_IF "verbose level" condition macro for sample cases, when some extra computation and preparation for logs is not needed.

  VLOG_IF(1, (size > 1024))
     << "I'm printed when size is more than 1024 and when you run the "
        "program with --v=1 or more";

We also override the standard 'assert' to use 'DLOG_ASSERT'.

Lastly, there is:

  PLOG(ERROR) << "Couldn't do foo";
  DPLOG(ERROR) << "Couldn't do foo";
  PLOG_IF(ERROR, cond) << "Couldn't do foo";
  DPLOG_IF(ERROR, cond) << "Couldn't do foo";
  PCHECK(condition) << "Couldn't do foo";
  DPCHECK(condition) << "Couldn't do foo";

which append the last system error to the message in string form (taken from GetLastError() on Windows and errno on POSIX).

The supported severity levels for macros that allow you to specify one are (in increasing order of severity) INFO, WARNING, ERROR, and FATAL.

Very important: logging a message at the FATAL severity level causes the program to terminate (after the message is logged).

There is the special severity of DFATAL, which logs FATAL in debug mode, ERROR in normal mode.

Macro Definition Documentation

◆ assert

#define assert (   x)    DLOG_ASSERT(x)

◆ CHECK

#define CHECK (   condition)
Value:
LAZY_STREAM(LOG_STREAM(FATAL), !(condition)) \
<< "Check failed: " #condition ". "
#define LOG_STREAM(severity)
Definition: cef_logging.h:286
#define LAZY_STREAM(stream, condition)
Definition: cef_logging.h:275

◆ CHECK_EQ

#define CHECK_EQ (   val1,
  val2 
)    CHECK_OP(EQ, ==, val1, val2)

◆ CHECK_GE

#define CHECK_GE (   val1,
  val2 
)    CHECK_OP(GE, >=, val1, val2)

◆ CHECK_GT

#define CHECK_GT (   val1,
  val2 
)    CHECK_OP(GT, >, val1, val2)

◆ CHECK_LE

#define CHECK_LE (   val1,
  val2 
)    CHECK_OP(LE, <=, val1, val2)

◆ CHECK_LT

#define CHECK_LT (   val1,
  val2 
)    CHECK_OP(LT, <, val1, val2)

◆ CHECK_NE

#define CHECK_NE (   val1,
  val2 
)    CHECK_OP(NE, !=, val1, val2)

◆ CHECK_OP

#define CHECK_OP (   name,
  op,
  val1,
  val2 
)
Value:
if (std::string* _result = cef::logging::Check##name##Impl( \
(val1), (val2), #val1 " " #op " " #val2)) \
cef::logging::LogMessage(__FILE__, __LINE__, _result).stream()

◆ COMPACT_GOOGLE_LOG_0

#define COMPACT_GOOGLE_LOG_0   COMPACT_GOOGLE_LOG_ERROR

◆ COMPACT_GOOGLE_LOG_DCHECK

#define COMPACT_GOOGLE_LOG_DCHECK   COMPACT_GOOGLE_LOG_FATAL

◆ COMPACT_GOOGLE_LOG_DFATAL

#define COMPACT_GOOGLE_LOG_DFATAL   COMPACT_GOOGLE_LOG_EX_DFATAL(LogMessage)

◆ COMPACT_GOOGLE_LOG_ERROR

#define COMPACT_GOOGLE_LOG_ERROR   COMPACT_GOOGLE_LOG_EX_ERROR(LogMessage)

◆ COMPACT_GOOGLE_LOG_EX_0

#define COMPACT_GOOGLE_LOG_EX_0 (   ClassName,
  ... 
)     COMPACT_GOOGLE_LOG_EX_ERROR(ClassName, ##__VA_ARGS__)

◆ COMPACT_GOOGLE_LOG_EX_DCHECK

#define COMPACT_GOOGLE_LOG_EX_DCHECK (   ClassName,
  ... 
)     COMPACT_GOOGLE_LOG_EX_FATAL(ClassName, ##__VA_ARGS__)

◆ COMPACT_GOOGLE_LOG_EX_DFATAL

#define COMPACT_GOOGLE_LOG_EX_DFATAL (   ClassName,
  ... 
)
Value:
::cef::logging::ClassName(__FILE__, __LINE__, ::cef::logging::LOG_DFATAL, \
##__VA_ARGS__)

◆ COMPACT_GOOGLE_LOG_EX_ERROR

#define COMPACT_GOOGLE_LOG_EX_ERROR (   ClassName,
  ... 
)
Value:
::cef::logging::ClassName(__FILE__, __LINE__, ::cef::logging::LOG_ERROR, \
##__VA_ARGS__)

◆ COMPACT_GOOGLE_LOG_EX_FATAL

#define COMPACT_GOOGLE_LOG_EX_FATAL (   ClassName,
  ... 
)
Value:
::cef::logging::ClassName(__FILE__, __LINE__, ::cef::logging::LOG_FATAL, \
##__VA_ARGS__)

◆ COMPACT_GOOGLE_LOG_EX_INFO

#define COMPACT_GOOGLE_LOG_EX_INFO (   ClassName,
  ... 
)
Value:
::cef::logging::ClassName(__FILE__, __LINE__, ::cef::logging::LOG_INFO, \
##__VA_ARGS__)

◆ COMPACT_GOOGLE_LOG_EX_WARNING

#define COMPACT_GOOGLE_LOG_EX_WARNING (   ClassName,
  ... 
)
Value:
::cef::logging::ClassName(__FILE__, __LINE__, ::cef::logging::LOG_WARNING, \
##__VA_ARGS__)

◆ COMPACT_GOOGLE_LOG_FATAL

#define COMPACT_GOOGLE_LOG_FATAL   COMPACT_GOOGLE_LOG_EX_FATAL(LogMessage)

◆ COMPACT_GOOGLE_LOG_INFO

#define COMPACT_GOOGLE_LOG_INFO   COMPACT_GOOGLE_LOG_EX_INFO(LogMessage)

◆ COMPACT_GOOGLE_LOG_WARNING

#define COMPACT_GOOGLE_LOG_WARNING   COMPACT_GOOGLE_LOG_EX_WARNING(LogMessage)

◆ DCHECK

#define DCHECK (   condition)
Value:
LAZY_STREAM(LOG_STREAM(DCHECK), DCHECK_IS_ON() && !(condition)) \
<< "Check failed: " #condition ". "
#define DCHECK_IS_ON()
Definition: cef_logging.h:458
#define DCHECK(condition)
Definition: cef_logging.h:532

◆ DCHECK_EQ

#define DCHECK_EQ (   val1,
  val2 
)    DCHECK_OP(EQ, ==, val1, val2)

◆ DCHECK_GE

#define DCHECK_GE (   val1,
  val2 
)    DCHECK_OP(GE, >=, val1, val2)

◆ DCHECK_GT

#define DCHECK_GT (   val1,
  val2 
)    DCHECK_OP(GT, >, val1, val2)

◆ DCHECK_IS_ON

#define DCHECK_IS_ON ( )    1

◆ DCHECK_LE

#define DCHECK_LE (   val1,
  val2 
)    DCHECK_OP(LE, <=, val1, val2)

◆ DCHECK_LT

#define DCHECK_LT (   val1,
  val2 
)    DCHECK_OP(LT, <, val1, val2)

◆ DCHECK_NE

#define DCHECK_NE (   val1,
  val2 
)    DCHECK_OP(NE, !=, val1, val2)

◆ DCHECK_OP

#define DCHECK_OP (   name,
  op,
  val1,
  val2 
)
Value:
if (DCHECK_IS_ON()) \
if (std::string* _result = cef::logging::Check##name##Impl( \
(val1), (val2), #val1 " " #op " " #val2)) \
cef::logging::LogMessage(__FILE__, __LINE__, ::cef::logging::LOG_DCHECK, \
_result) \
.stream()

◆ DEFINE_CHECK_OP_IMPL

#define DEFINE_CHECK_OP_IMPL (   name,
  op 
)
Value:
template <class t1, class t2> \
inline std::string* Check##name##Impl(const t1& v1, const t2& v2, \
const char* names) { \
if (v1 op v2) \
return NULL; \
else \
return MakeCheckOpString(v1, v2, names); \
} \
inline std::string* Check##name##Impl(int v1, int v2, const char* names) { \
if (v1 op v2) \
return NULL; \
else \
return MakeCheckOpString(v1, v2, names); \
}

◆ DLOG

#define DLOG (   severity)    LAZY_STREAM(LOG_STREAM(severity), DLOG_IS_ON(severity))

◆ DLOG_ASSERT

#define DLOG_ASSERT (   condition)    LOG_ASSERT(condition)

◆ DLOG_IF

#define DLOG_IF (   severity,
  condition 
)    LOG_IF(severity, condition)

◆ DLOG_IS_ON

#define DLOG_IS_ON (   severity)    LOG_IS_ON(severity)

◆ DPCHECK

#define DPCHECK (   condition)
Value:
LAZY_STREAM(PLOG_STREAM(DCHECK), DCHECK_IS_ON() && !(condition)) \
<< "Check failed: " #condition ". "
#define PLOG_STREAM(severity)
Definition: cef_logging.h:333

◆ DPLOG

#define DPLOG (   severity)    LAZY_STREAM(PLOG_STREAM(severity), DLOG_IS_ON(severity))

◆ DPLOG_IF

#define DPLOG_IF (   severity,
  condition 
)    PLOG_IF(severity, condition)

◆ DVLOG

#define DVLOG (   verboselevel)    DVLOG_IF(verboselevel, VLOG_IS_ON(verboselevel))

◆ DVLOG_IF

#define DVLOG_IF (   verboselevel,
  condition 
)    VLOG_IF(verboselevel, condition)

◆ DVPLOG

#define DVPLOG (   verboselevel)    DVPLOG_IF(verboselevel, VLOG_IS_ON(verboselevel))

◆ DVPLOG_IF

#define DVPLOG_IF (   verboselevel,
  condition 
)    VPLOG_IF(verboselevel, condition)

◆ EAT_STREAM_PARAMETERS

#define EAT_STREAM_PARAMETERS    true ? (void)0 : ::cef::logging::LogMessageVoidify() & LOG_STREAM(FATAL)

◆ ENABLE_DLOG

#define ENABLE_DLOG   1

◆ ERROR

#define ERROR   0

◆ LAZY_STREAM

#define LAZY_STREAM (   stream,
  condition 
)     !(condition) ? (void)0 : ::cef::logging::LogMessageVoidify() & (stream)

◆ LOG

#define LOG (   severity)    LAZY_STREAM(LOG_STREAM(severity), LOG_IS_ON(severity))

◆ LOG_ASSERT

#define LOG_ASSERT (   condition)     LOG_IF(FATAL, !(condition)) << "Assert failed: " #condition ". "

◆ LOG_IF

#define LOG_IF (   severity,
  condition 
)     LAZY_STREAM(LOG_STREAM(severity), LOG_IS_ON(severity) && (condition))

◆ LOG_IS_ON

#define LOG_IS_ON (   severity)     ((::cef::logging::LOG_##severity) >= ::cef::logging::GetMinLogLevel())

◆ LOG_STREAM

#define LOG_STREAM (   severity)    COMPACT_GOOGLE_LOG_##severity.stream()

◆ NOTIMPLEMENTED

#define NOTIMPLEMENTED ( )    LOG(ERROR) << NOTIMPLEMENTED_MSG

◆ NOTIMPLEMENTED_MSG

#define NOTIMPLEMENTED_MSG   "NOT IMPLEMENTED"

◆ NOTIMPLEMENTED_POLICY

#define NOTIMPLEMENTED_POLICY   4

◆ NOTREACHED

#define NOTREACHED ( )    DCHECK(false)

◆ PCHECK

#define PCHECK (   condition)
Value:
LAZY_STREAM(PLOG_STREAM(FATAL), !(condition)) \
<< "Check failed: " #condition ". "

◆ PLOG

#define PLOG (   severity)    LAZY_STREAM(PLOG_STREAM(severity), LOG_IS_ON(severity))

◆ PLOG_IF

#define PLOG_IF (   severity,
  condition 
)     LAZY_STREAM(PLOG_STREAM(severity), LOG_IS_ON(severity) && (condition))

◆ PLOG_STREAM

#define PLOG_STREAM (   severity)
Value:
COMPACT_GOOGLE_LOG_EX_##severity(Win32ErrorLogMessage, \
::cef::logging::GetLastSystemErrorCode()) \
.stream()

◆ SYSLOG

#define SYSLOG (   severity)    LOG(severity)

◆ SYSLOG_ASSERT

#define SYSLOG_ASSERT (   condition)     SYSLOG_IF(FATAL, !(condition)) << "Assert failed: " #condition ". "

◆ SYSLOG_IF

#define SYSLOG_IF (   severity,
  condition 
)    LOG_IF(severity, condition)

◆ VLOG

#define VLOG (   verbose_level)     LAZY_STREAM(VLOG_STREAM(verbose_level), VLOG_IS_ON(verbose_level))

◆ VLOG_IF

#define VLOG_IF (   verbose_level,
  condition 
)
Value:
LAZY_STREAM(VLOG_STREAM(verbose_level), \
VLOG_IS_ON(verbose_level) && (condition))
#define VLOG_IS_ON(verboselevel)
Definition: cef_logging.h:270
#define VLOG_STREAM(verbose_level)
Definition: cef_logging.h:296

◆ VLOG_IS_ON

#define VLOG_IS_ON (   verboselevel)     ((verboselevel) <= ::cef::logging::GetVlogLevel(__FILE__))

◆ VLOG_STREAM

#define VLOG_STREAM (   verbose_level)     cef::logging::LogMessage(__FILE__, __LINE__, -verbose_level).stream()

◆ VPLOG

#define VPLOG (   verbose_level)     LAZY_STREAM(VPLOG_STREAM(verbose_level), VLOG_IS_ON(verbose_level))

◆ VPLOG_IF

#define VPLOG_IF (   verbose_level,
  condition 
)
Value:
LAZY_STREAM(VPLOG_STREAM(verbose_level), \
VLOG_IS_ON(verbose_level) && (condition))
#define VPLOG_STREAM(verbose_level)
Definition: cef_logging.h:307

◆ VPLOG_STREAM

#define VPLOG_STREAM (   verbose_level)
Value:
cef::logging::Win32ErrorLogMessage(__FILE__, __LINE__, -verbose_level, \
::cef::logging::GetLastSystemErrorCode()) \
.stream()

Function Documentation

◆ operator<<() [1/2]

std::ostream& operator<< ( std::ostream &  out,
const std::wstring &  wstr 
)
inline

◆ operator<<() [2/2]

std::ostream& operator<< ( std::ostream &  out,
const wchar_t *  wstr 
)