Skip to content

Console Output

Eduard Mishkurov edited this page Jan 7, 2026 · 4 revisions

Console Output and Colors

logme supports colored console output on both Linux and Windows.

Color handling is designed to work correctly across different console capabilities and operating system versions.


Color Support Overview

Console color output in logme works in two modes:

  1. Classic console colors (16 colors)
  2. ANSI / VT mode (extended formatting)

By default, only classic console coloring is enabled. ANSI / VT mode must be enabled explicitly.

Both modes are supported on Windows. Linux uses ANSI sequences natively.


Enabling VT Mode on Windows

To enable ANSI / VT processing on Windows, the application must explicitly request it:

Logme::Instance->SetEnableVTMode(true);

If VT mode is successfully enabled:

  • ANSI escape sequences are supported
  • Extended colors become available
  • Text attributes such as underline and bold can be used

If VT mode is not enabled or not supported:

  • Output falls back to classic console coloring
  • ANSI escape sequences are automatically stripped

Windows Console Behavior

Classic Console Mode (No VT)

Even if VT mode is not enabled, logme still supports:

  • 16-color console output
  • Automatic severity-based coloring
  • Colored warnings and errors

In this mode:

  • Colors are applied using native Windows console APIs
  • ANSI escape sequences are not required
  • Automatic coloring works transparently

Severity-based coloring:

  • Info — default console color
  • Warning — yellow
  • Error / Critical — red

Automatic Highlighting Control

Automatic severity-based coloring can be disabled.

This is controlled by OutputFlags.Highlight (console backend only).

If Highlight is disabled:

  • No automatic coloring based on severity is applied
  • User-provided ANSI formatting (if VT mode is enabled) still works

This allows precise control over visual output, especially when console colors are managed externally.


Linux Console Behavior

On Linux:

  • ANSI escape sequences are supported natively
  • VT mode handling is not required
  • Extended colors and formatting work out of the box

Manual ANSI Color Sequences

Applications may include ANSI color sequences directly in log messages.

To use predefined ANSI constants, include:

#include <Logme/AnsiColorEscape.h>

Example:

LogmeI(
  ANSI_LIGHT_GREEN "green text "
  ANSI_YELLOW "yellow "
  ANSI_RESET "normal"
);

When VT mode is enabled:

  • Colors and attributes are rendered as specified

When VT mode is disabled:

  • ANSI sequences are removed automatically

stdout / stderr Routing

The Console backend supports flexible routing of log messages between stdout and stderr using ConsoleStream in OutputFlags.

This allows correct integration with shells, supervisors, and log collectors.

Clone this wiki locally