Logging Library Errors

We recommend using the Logger to log any error messages while developing your app.

Defining a Custom Logger

If you're using the low-level renderer (eg, Renderer::Create()), you'll need to define your own custom logger to handle these log messages.

Here's an example:

#include <cstdio>

using namespace ultralight;

// Define our custom Logger class
class MyLogger : public Logger {
public:
  MyLogger() {}
  virtual ~MyLogger() {}

  ///
  /// Called when the library wants to print a message to the log.
  ///
  virtual void LogMessage(LogLevel log_level, const String& message) override {
    printf("%s\n", message.utf8().data());
  }
};

// In your initialization routine:
void InitApp() {
  // Tell the library to use our custom Logger class
  Platform::instance().set_logger(new MyLogger());
  
  // Create renderer, views, etc.
}

Logging Messages with AppCore

If you're using AppCore (eg, App::Create()), a default Logger is already defined for you that writes output to a log file.

The location of this log file differs on each Platform:

Replace MyCompany with Settings.developer_name and MyApp with Settings.app_name if you've changed these values in Settings

PlatformPath
WindowsC:\Users\<User>\AppData\Roaming\MyCompany\MyApp\ultralight.log
macOS~/Library/Caches/com.MyCompany.MyApp/ultralight.log
Linux~/.cache/MyCompany-MyApp/ultralight.log