Skip to content

Getting Started

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

Getting Started

logme can be used immediately without any configuration, or gradually extended to a fully dynamic setup.

This page describes the three main usage models.

1. Default Setup (No Configuration)

If the application does not configure logme explicitly, a default channel is created automatically.

Default behavior:

  • A default channel exists
  • Console output is enabled
  • Debugger output is enabled on Windows (only in Debug builds)
  • Reasonable formatting and severity filtering is applied

This setup is often sufficient for:

  • Small tools
  • Utilities
  • Early development stages

2. Hardcoded Setup (Programmatic Configuration)

In this model, channels and backends are created explicitly in code.

Typical use cases:

  • Highly constrained environments
  • Applications with fixed logging topology
  • Custom backend logic

Example

#include <Logme/Logme.h>
#include <Logme/Backend/ConsoleBackend.h>

int main()
{
  auto root = Logme::Instance->CreateChannel("root");
  root->AddBackend(std::make_shared<ConsoleBackend>(root));

  auto http = Logme::Instance->CreateChannel("http");
  http->AddLink(root);

  // Goes to http backends (if any), then to root
  fLogmeI(http, "GET {} -> {}", "/index.html", 200);
  return 0;
}

3. JSON-based Setup

In this model, the entire logging topology is described in a JSON configuration file.

Advantages:

  • No recompilation required
  • Runtime reconfiguration
  • Suitable for production systems

JSON configuration can be reloaded dynamically.

Example configuration (config.json)

This configuration creates the following logging setup:

  • A default channel (channel with an empty name "") is created.

    • The log level is set to Info, meaning all messages except Debug are allowed.
    • Three backends are attached to this channel:
      • ConsoleBackend — always enabled.
      • DebugBackend — created only on Windows and only in Debug builds.
      • FileBackend — opens log.txt in append mode (existing log is preserved). The file path is relative and the file is created inside the logger home directory specified via Logger::SetHomeDirectory().
  • A channel named http is created.

    • This channel has no backends of its own.
    • It is linked to the default channel, so all messages written to http are forwarded to the default channel and processed by its backends.
{
  "channels": [
    {
      "name": "",
      "level": "info",
      "backends": [
        { "type": "ConsoleBackend" },
        {
          "type": "DebugBackend",
          "platform": "windows",
          "build": "debug"
        },
        {
          "type": "FileBackend",
          "file": "log.txt",
          "append": true
        }
      ]
    },
    {
      "name": "http",
      "link": ""
    }
  ]
}

Clone this wiki locally