Debugging C++

This page describes how to debug Molybden application backend written in C++ in your favorite IDE.

The application backend is written in C++. It is responsible for creating the application window, displaying native system dialogs, managing the application life cycle, making calls to the operating system and third party libraries, and communicating with the application JavaScript frontend.

To simplify the process of the application backend development and debugging, Molybden creates the CMakeLists.txt file in the project directory. You can open this file in your favorite C++ IDE that supports CMake projects and debug the application backend as a regular C++ application.

Debugging in CLion

CLion is a cross-platform C++ IDE developed by JetBrains. It supports CMake projects and provides a convenient way to debug C++ applications.

To start debugging the application backend in CLion, open the CMakeLists.txt file in CLion:

Open CMakeLists.txt in CLion

Open SettingsBuild, Execution, DeploymentCMake and switch to the Debug build type:

Switch to the Debug build type

Click the Debug button in the top right corner of the IDE window.

Debug app in CLion

CLion will build the application backend and start the debug session.


During debugging, you might want to enable logging to access valuable information, track the flow of execution, identify potential issues, diagnose and fix problems more efficiently.

Molybden provides a flexible logging system that allows you to enable logging, specify the logging destination, and control the logging level.

You can use the logging system for the following debugging purposes:

  1. To log messages from your application code.
  2. To get log messages from Molybden internals.

Enabling logging

By default, logging is disabled to minimize overhead and improve performance in production environments.

To enable logging use the following approach:

#include "molybden.hpp"

using namespace molybden;

void launch() {
  AppOptions options;
  // Enable application logging.
  options.logging.enabled = true;
  App::init(options, [](std::shared_ptr<App> app) {
    // Create a new browser window.

Logging levels

The logging system supports the following logging levels (see molybden::LogLevel):

Level Description
kInfo Level used for informational messages. This is the most common severity level.
kWarning Level used for warning messages.
kError Level used for error messages.
kFatal Level used for messages that indicate fatal errors that occur during the application lifecycle. The application will be terminated after a message with this level is logged.

By default, the logging system logs messages with the kInfo level and higher. You can change the logging level using the following approach:

options.logging.log_level = molybden::LogLevel::kError;

Pay attention to the kFatal level. If you enable logging with the kFatal level, the application will be terminated after a message with this level is logged.

Logging destinations

The log messages can be written to the application standard output or to a file.

Standard output

Once logging is enabled, log messages are directed to the standard output. The application will automatically display log messages in the console or terminal window where your application is running.

If you run the application as a regular GUI application that doesn’t display a console window with the standard output, you won’t see the log message. In this case we recommend that you log messages to a file.

Log file

To log messages to a file use the following approach:

options.logging.destination = molybden::Destination::kFile;
options.logging.log_file = "/Users/me/MyApp/molybden.log";

By directing logs to a file, you can store them for later analysis, share them with your team, or archive them for historical purposes.

Important: Ensure that the specified file path is accessible and has the necessary write permissions for successful logging.

Log messages

To log messages from your application code with the specified logging level use the following approach:

LOG(INFO) << "This is an informational message: " << data;
LOG(WARNING) << "This is a warning message: " << data;
LOG(ERROR) << "This is an error message: " << data;
LOG(FATAL) << "This is a fatal message: " << data;

The << operator supports the following types:

  • C++ built-in types i.e, int, float, double, char, bool, etc.
  • std::string.
  • void*, pointers to fundamental types, pointers to user-defined types, smart pointers.

To make a custom class or struct loggable, you must provide an appropriate << operator overload implementation. For example:

class MyClass {
  friend std::ostream& operator<<(std::ostream& os, const MyClass& myClass) {
    os << myClass.data_;
    return os;

  int data_;


The log messages include a lot of information required for debugging. All the sensitive information like login, passwords, keyboard and mouse events, dragged text, product license key, etc. is excluded from the Molybden log messages and replaced with asterisks (***).

On this page