Skip to content

Glog Compatibility

Eduard Mishkurov edited this page Jun 19, 2026 · 1 revision

glog Compatibility Macros

logme provides an optional compatibility header for projects migrating from Google glog:

#include <Logme/GlogCompat.h>

This header defines familiar glog-style macros such as LOG, CHECK, PLOG, DLOG, VLOG, LOG_FIRST_N, and LOG_EVERY_N.

The compatibility layer is intentionally separate from the main Logme.h API because names such as LOG, CHECK, INFO, and ERROR are very broad and may conflict with application code or platform headers.

Basic LOG mapping

glog-style macro logme target
LOG(INFO) LogmeI()
LOG(WARNING) LogmeW()
LOG(ERROR) LogmeE()
LOG(FATAL) LogmeC()
LOG_IF(level, condition) conditional logme stream call

Example:

LOG(INFO) << "server started";
LOG_IF(WARNING, queueSize > limit) << "queue is large: " << queueSize;

LOG(FATAL) writes a critical log record. It terminates the process only when the application installs a fatal handler. See Fatal Handling and Critical Logs.

CHECK macros

The compatibility header maps check macros to critical log records:

CHECK(ptr != nullptr) << "missing object";
CHECK_EQ(actual, expected) << "unexpected value";
CHECK_NOTNULL(ptr)->Run();

Supported checks include:

CHECK(condition)
CHECK_EQ(left, right)
CHECK_NE(left, right)
CHECK_LT(left, right)
CHECK_LE(left, right)
CHECK_GT(left, right)
CHECK_GE(left, right)
CHECK_NOTNULL(pointer)

The comparison arguments are evaluated once. When a comparison fails, logme writes the expressions and values to the critical record.

The process is not aborted by the macro itself. The termination policy is controlled by Logger::SetFatalHandler().

PLOG and PCHECK

PLOG and PCHECK add the current system error text to the message:

PLOG(ERROR) << "open failed";
PCHECK(fd >= 0) << "open failed";

On POSIX systems the current errno value is captured. On Windows the current GetLastError() value is captured. The error is captured before the message body is streamed, so later code does not accidentally overwrite it.

Native logme equivalents are also available:

LogmeE_P() << "open failed";
LogmePCheck(fd >= 0) << "open failed";

DLOG and DCHECK

DLOG and DCHECK are debug-build-only compatibility macros.

When NDEBUG is not defined, they behave like the corresponding LOG and CHECK macros:

DLOG(INFO) << "debug-only detail";
DCHECK(ptr != nullptr) << "debug-only check";

When NDEBUG is defined, the macros compile to no-op forms and the stream expressions are not evaluated.

This is different from LogmeD. LogmeD is a normal debug-level log record and can be useful in release builds when runtime diagnostics are enabled. DLOG is specifically for glog-style debug-build-only migration.

VLOG

VLOG(n) in glog means verbose logging controlled by a numeric verbosity level. It is not a severity level. A message such as VLOG(2) is written as an INFO-style record only when the configured verbosity is at least 2.

In the logme compatibility header this is controlled by LOGME_GLOG_VLOG_LEVEL:

#define LOGME_GLOG_VLOG_LEVEL 2
#include <Logme/GlogCompat.h>

VLOG(1) << "basic verbose detail";
VLOG(3) << "not written when level is 2";

VLOG_IF(n, condition) combines the verbosity check with a condition. VLOG_IS_ON(n) checks whether a verbosity level is currently enabled.

This exists for migration. New logme code should usually prefer named diagnostics: channels, subsystems, trace points, and runtime control. A numeric VLOG(3) does not explain what is being enabled. A named trace point or subsystem is easier to manage in production.

The compatibility layer does not implement glog --vmodule rules. Use logme trace points or subsystem filters for production-controlled selective diagnostics.

First N and every N

The compatibility header supports count-based rate macros:

LOG_FIRST_N(INFO, 3) << "printed only for the first three attempts";
LOG_EVERY_N(WARNING, 100) << "printed every 100th attempt";

Native logme equivalents are available as level-specific macros:

LogmeI_FirstN(3) << "first three attempts";
LogmeW_EveryN(100) << "every 100th attempt";

These are count-based controls. They complement logme's time-based _Every(ms) macros and collapse macros.

What is not emulated

RAW_LOG is not implemented by GlogCompat.h.

glog raw logging has a special low-level contract around allocation, locking, and emergency paths. The normal logme path uses the regular logging infrastructure, so pretending to provide RAW_LOG through the same path would be misleading.

If an application requires a true raw emergency logger, it should use a dedicated low-level path or application-specific crash handler.

Migration guidance

The compatibility header is useful for the first stage of migration. It lets existing code keep familiar glog-style macros while logme handles the records.

After the initial migration, prefer native logme mechanisms where they express intent better:

  • replace numeric VLOG(n) with trace points or subsystem filters;
  • replace repeated LOG_EVERY_N use with _Every(ms) or collapse macros when time-based behavior is more useful;
  • use channels and backend routing instead of global logger assumptions;
  • install a fatal handler when the project wants glog-like CHECK/FATAL termination.

Clone this wiki locally