- OpenSceneGraph 3.0: Beginner's Guide
- Rui Wang Xuelei Qian
- 201字
- 2021-03-27 00:35:43
Tracing with the notifier
The OSG notifier mechanism provides a novel method of outputting verbose debugging messages, either from the OSG rendering backend or from the user level. It is really an important and time-honored method for tracing and debugging programs. In addition, the notifier is also used throughout the OSG core functionalities and plugins to show errors, warning messages, or information about the work in progress. Developers may simply insert debugging print functions liberally in the source code files. The print function, osg::notify()
, is designed to accept different levels of messages and send them to the console or user-defined controllers.
The osg::notify()
function can be used as the standard output stream std::cout
. It requires a NotifySeverity
argument to indicate the message level, which can be ALWAYS, FATAL, WARN, NOTICE, INFO, DEBUG_INFO
, and DEBUG_FP
, sorted from the most severity to the least. For instance:
osg::notify(osg::WARN) << "Some warn message." << std::endl;
This will print out a line of the warning message by default. Here osg::WARN
is used to indicate the notify level to the OSG notifier system.
A series of macro definitions, such as OSG_FATAL, OSG_WARN
, and OSG_NOTICE
, will do the same work as the osg::notify()
function, with different severity levels.