Skip to content

Logging

Alex Krieg edited this page Oct 15, 2024 · 2 revisions

Logging

TitleImage


Logger Library Repository Logging is based on the Logger library. Visit it to learn it in detail.

Open a Console

Native Console View

The simplest console is the native console view. It's just a black console window. To be able to receive log messages, a instance of the console view must be created. Call this code in the constructor of your MainWindow or the main.cpp.

Log::UI::NativeConsoleView::createStaticInstance();
Log::UI::NativeConsoleView::getStaticInstance()->show();

Qt Console View

You can add a Qt Widget based console, for example:

Log::UI::QConsoleView::createStaticInstance();
Log::UI::QConsoleView::getStaticInstance()->show();

Qt Tree Console View

Log::UI::QTreeConsoleView::createStaticInstance();
Log::UI::QTreeConsoleView::getStaticInstance()->show();

Plot to file

If you want to stream the log messages to a file, you can create a FilePlotter instance. As long as this instance exists, it plots all messages to the file.

Log::FilePlotter plotter("logfile.log");

Logging in a GameObject

By default if you call the log methodes on a GameObject: this->log("MessageText").
It will be in the context of the Scene the object is in.
But a custom logger instance can be created for the GameObject. To do so, call obj->createLogger().
That function creates a logger instance for the GameObject. Every child object will now log to that logger.
The logger has the same name as the Object.
If you create custom loggers for all GameObjects within a object tree, than the loggers will be arranged to fit the same tree structure.
This is usefull if the Log::UI::QTreeConsoleView is used.

Logging in a Component

For easy debugging, you can print messages to the console.
Each Component contains a interface to the logging system of the Scene.
Logging is only available if the component is in a GamaObject that is contained within a Scene.
Inside your Component, call: this->log("MessageText")