SG LOG

From FlightGear wiki
Jump to navigation Jump to search

SG_LOG is a wrapper macro for the SimGear logstream class. By default, the logstream class writes all output to the console. SG_LOG simplifies debugging for core developers who regularly compile from source. It allows you to easily associate your debug messages with a "channel" and with a "priority". This mechanism allows users to explicitly enable to certain log messages, while ignoring others. This can be helpful in order to troubleshoot certain problems.

Usage

Logging settings can be modified using the --log-level=[level] and --log-class=[class] command line options. Where level is one of the following:

  • bulk
  • debug
  • info
  • warn
  • alert
  • popup

And class is a white space seperated list of any (combination) of the following:

  • all
  • ai
  • enviroment
  • flight
  • etc.

For a complete list of available classes, see simgear/simgear/debug/debug_types.h.

In the C++-code, log output can be generated like this: SG_LOG(SG_INSTR, SG_DEBUG, "Test=" << someVar); and shown with --log-level=debug --log-class=instrumentation.

If you are interested in simply logging certain properties to a file at runtime, you can use either FlightGear's built-in logging framework, or the generic protocol.

File/line numbers

Log output will be prefixed with <filename>:<line>: if Flightgear is started with command-line option --prop:bool:/sim/log-file-line=true.

Text output from Nasal will be prefixed with <nasal-filename>:<line>: if Flightgear is started with command-line option --prop:bool:/sim/nasal-log-file-line=true.

Log deltas

On can modify log levels based on the file/function-name/line-number of calls to SG_LOG(), by setting the environmental variable SG_LOG_DELTAS when running Flightgear.

For example one can increase debugging diagnostics from scenery paging code with:

SG_LOG_DELTAS=src/Scenery/SceneryPager.cxx=+3 fgfs.exe ...

Or set to =-5 to reduce all diagnostics by 5:

SG_LOG_DELTAS==-5 fgfs.exe ...

For more information see: simgear/simgear/debug/logdelta.hxx.

Related content

Wiki articles

Source code