Text output

There are several ways to print text information (e.g. messages for user or developer) in vrecko:

  • (Recommended) Use the Logger class (built-in part of vrecko) and format strings the same way as if you’re using an ordinary printf() function.
  • Use the standard C++ streams (std::cout, std::cerr).
  • Use the standard C function printf().

Usage of the Logger class allows you to separate strings into categories and turn off debugging logs for the user after the optimization.

All of the aforementioned ways are automatically redirected so that they print information simultaneously into the text console, the Visual Studio output window and into the vrecko log file.

If you’re using the Console ability (located in the TextOutput plug-in), each way also prints the text graphically to the upper part of the screen – a small console will appear which will roll down after the text is printed and disappear after inactivity.

(Possibly obsolete information: If you include the vr_base.xml configuration file in your project, this console is active by default.)

First way – Logger

There are two ways how to use the Logger class. You may either include its header file and use the already existing global instance or – even more simply – access the logger functionality using the global world variable. In the second case, vrecko/Logger.h does not have to be included because this functionality is also present in world.

 

#include <vrecko/Logger.h>
...
...
...
logger.noticeLog();

Example 1: Inclusion of the header file and calling the global variable.

world->noticeLog();

Example 2: Accessing the functionality of the Logger class using global variable world.

 

The Logger class contains various log functions which should be used in different scenarios:

  • errorLog() – important error which should be seen by user ("Error loading table.obj.").
  • warningLog() – warning for the user ("Audio not found, no sound will play.").
  • noticeLog() – common information for the user ("The scene was saved.").
  • debugLog() – debug information only ("vector1 = 0.3, 0.4, 2.2").
  • debugFileLog() – debug information which will only be written to the file and will not appear on the screen or console.

By default, all passed messages are printed but it can be restricted by calling the logger.setAllowedOutput() method which will be told which types should only be printed.

To achieve this, use a combination (bitwise OR) of numeric constants such as

  • LOGGER_OUTPUTTYPE_ERROR
  • LOGGER_OUTPUTTYPE_WARNING
  • LOGGER_OUTPUTTYPE_NOTICE
  • LOGGER_OUTPUTTYPE_DEBUG
  • etc.

Alternatively, you may use one of the already predefined masks such as

  • LOGGER_OUTPUTTYPEMASK_ALL
  • LOGGER_OUTPUTTYPEMASK_NONE
  • LOGGER_OUTPUTTYPEMASK_NORMAL
  • etc.

The full list and description of constants can be found in the file vrecko/Logger.h.

Moreover, it is also possible to use the environment variable VRECKO_OUTPUT, which can be set numerically same as with setAllowedOutput() or symbolically by one of the strings ALL or DEBUG (the same), NORMAL or USER (the same, but without debug messages) or NONE (completely disabled).

Note: In Windows it is possible to change the environment variables in Control Panel -> System. However, if you’re launching vrecko from Visual Studio, the change in user variables will be only applied after restarting the whole Visual Studio application!

Second way – std::cout / std::cerr

vrecko is also able to detects this way which means that all notes in the previous section apply. cout behaves the same way as printing through debugLog() while cerr works the same way as errorLog().

Setting the log destination

You can set where the logs are sent with the new environment variable VRECKO_OUTPUT_DEST.

By default, they are sent to the following places:

  • std::cout, i.e. the text console ( = 1)
  • Log-file in the <vreckoDIR>\vrecko\bin\log folder ( = 2 )
  • Visual Studio console (with the OutputDebugString() function) ( = 4 )
  • Graphical console on the screen (no constant assigned).

We may want to disable some of that – e.g. log-files because of performance issues. To achieve that, we can set the environment variable to 6. This denotes the combination of the outputs 2+4 while leaving 1 out. However, it is much better to use one of the already predefined alternative texts:

  • ALL
  • NONE
  • NO_STDOUT
  • NO_FILE
  • NO_DEBUGSTRING

Therefore we would use set VRECKO_OUTPUT_DEST=NO_STDOUT in the previous example (be cautious – there can be no spaces around the “=” character)

The graphical console is controlled differently – if you wish to disable it, simply don’t include the Console ability in the scene.

(Possibly obsolete information: It is in vr_base.xml, so it’s necessary to make a copy of this file and modify it, or delete it in another XML file using the delete flag – see the merging files section in XML Files.)