Console Logging on the BlackBerry 10 Native SDK Beta 3



By Tehdog (Own work) [CC0], via Wikimedia Commons (Mute_Icon.svg, Speaker Icon.svg)

Some of you may have noticed that the Beta 3 release of the BlackBerry® 10 Native SDK got a bit quieter in the console when creating Cascades™ applications. As of Qt 4.8.3, all output that used to code to the console (qDebug(), qWarning(), qCritical() etc) is now output to slog2. This not only affects the logging from C++ but also any console.log() JavaScript logging done from within QML as well as error messages at runtime. No console output can make troubleshooting even simple issues very frustrating. Luckily there are a few workarounds detailed in the “Known limitations” section of the release notes that can get you access to the logging information.

1) This workaround gets you the logging information back to the console, but should be removed prior to publishing your application to the BlackBerry App World™ storefront. Either of the following can be done:

a. Use the fprintf() function with stdout or stderr as the output stream to receive output directly to the console. This is easy to do to add in-line console output from C++, but will not restore logging to the console from QML.
ex fprintf(stdout, “I am a console message\n”);

b. Register your own message handler with the application to have all qDebug() (etc) and QML output handled however you wish (including using fprintf() as mentioned above). To do this, open your main.cpp file (the default main file for a Cascades application) and add a function similar to the following above the main method:

void myMessageOutput(QtMsgType type, const char* msg){
               fprintf(stdout, "%s\n", msg);

Then in the main method we need to register the above method as a message handler:

int main(int argc, char **argv)
    Application app(argc, argv);

After this is done you will once again have console output!

2) To see debug information that is output from qDebug(), you can access the slogger2 logs as follows:

In the IDE, in the Target Navigator view, right-click the device target. Click Launch SSH Session.

In the terminal that appears, do one of the following:

  • To view the current slogger2 logs, type slog2info.
  • To view real-time output for the processes that are being debugged (for applications that are running in development mode), type slog2info -w.
  • To view help information on slogger2, type slog2info -h.

You can also access the log files directly in the /tmp/slogger22 on the device and run these logs through slog2info at a later time.

This works well to retrieve all logs, but has a bit more overhead than option 1b) and also does not allow you to see the logs in the console.

Now you have a few options to get access to the application logs, which can be used in the interim until a solution comes in a future NDK release and the above workarounds are no longer needed.

The workarounds mentioned above are also covered in the following places:

Join the conversation

Show comments Hide comments
+ -