SG LOG: Difference between revisions

From FlightGear wiki
Jump to navigation Jump to search
No edit summary
 
(4 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{merge|SG_LOG()}}
<code>SG_LOG</code> is a wrapper macro for the [[SimGear]] <code>logstream</code> class.  By default, the <code>logstream</code> class writes all output to the [[console]].  <code>SG_LOG</code> simplifies debugging for core developers who regularly [[Building FlightGear|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.


<code>SG_LOG</code> is a wrapper macro for the [[SimGear]] <code>logstream</code> class.  By default, the <code>logstream</code> class writes all output to the console.  <code>SG_LOG</code> simplifies debugging for core developers who regularly [[Building FlightGear|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 <code>--log-level=[level]</code> and <code>--log-class=[class]</code> [[command line]] options. Where <code>level</code> is one of the following:
* <code>bulk</code>
* <code>debug</code>
* <code>info</code>
* <code>warn</code>
* <code>alert</code>
* <code>popup</code>
And <code>class</code> is a white space seperated list of any (combination) of the following:
* <code>all</code>
* <code>ai</code>
* <code>enviroment</code>
* <code>flight</code>
* etc.


Logging settings can be modified using the <code>--log-level=[level]</code> [[command line]] option, detailed help about most available command line options can be obtained from the fgfs executable by calling it with the following arguments: <code>--help --verbose</code>.
For a complete list of available classes, see {{simgear file|simgear/debug/debug_types.h}}.


<pre>
In the C++-code, log output can be generated like this: <code>SG_LOG(SG_INSTR, SG_DEBUG, "Test=" << someVar);</code> and shown with <code>--log-level=debug --log-class=instrumentation</code>.
--log-level={bulk,debug,info,warn,alert}
                                Specify which logging level to use


--log-class=[ai,environment,flight,general,io,network,sound,terrain,...]
If you are interested in simply logging certain properties to a file at runtime, you can use either FlightGear's built-in [[Logging properties|logging framework]], or the [[generic protocol]].
                                Specify which logging class(es) to use


</pre>
== File/line numbers ==


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]].  See [[Logging properties]] and [[Generic protocol]] for more details.
Log output will be prefixed with <code>&lt;filename&gt;:&lt;line&gt;:</code> if Flightgear is started with command-line option <code>--prop:bool:/sim/log-file-line=true</code>.


{{FGCquote
Text output from Nasal will be prefixed with <code>&lt;nasal-filename&gt;:&lt;line&gt;:</code> if Flightgear is started with command-line option <code>--prop:bool:/sim/nasal-log-file-line=true</code>.
  |The standard mechanism for making FlightGear "log" stuff to the console (or log file) is using the SG_LOG() macro
  |{{cite web |url=http://forum.flightgear.org/viewtopic.php?p=233211#p233211
    |title=<nowiki>Re: 3.4 and the pain begins ...</nowiki>
    |author=<nowiki>Hooray</nowiki>
    |date=<nowiki>Thu Feb 26</nowiki>
  }}
}}


== Development ==
== Log deltas ==
{{FGCquote
 
  |'m working a bit on reworking the logging exposed to Nasal, since it hasn't been updated in years (besides the addition of the never-used logprint() by James, the old printlog() only goes to the $FG_HOME/fgfs.log file if it would also go to the console and is implemented in globals.nas - aka can't be depended on in $FG_ROOT/Nasal/*.nas). This is going to eventually help with the Nasal REPL (aka to capture output), but I discovered something really weird: sglog().would_log() returns true for any priority &gt;{{=}} INFO! This almost seems like a bug to me, but OTOH it is required by the SG_LOG() macro to ensure that the logging file is not ignored in the if statement (since SG_LOG() uses would_log()).
On can modify log levels based on the file/function-name/line-number of calls to <code>SG_LOG()</code>, by setting the environmental variable <code>SG_LOG_DELTAS</code> when running Flightgear.
  |{{cite web |url=http://forum.flightgear.org/viewtopic.php?p=202850#p202850
 
    |title=<nowiki>sglog().would_log()</nowiki>
For example one can increase debugging diagnostics from scenery paging code with:
    |author=<nowiki>Philosopher</nowiki>
 
    |date=<nowiki>Fri Mar 07</nowiki>
<code>SG_LOG_DELTAS=src/Scenery/SceneryPager.cxx=+3 fgfs.exe ...</code>
  }}
 
}}
Or set to <code>=-5</code> to reduce all diagnostics by 5:
 
<code>SG_LOG_DELTAS==-5 fgfs.exe ...</code>
 
For more information see: {{simgear file|simgear/debug/logdelta.hxx}}.


== Related content ==
== Related content ==
=== Wiki articles ===
=== Wiki articles ===
* [[Command line options#Debugging Options]]
* [[Command line options#Debugging Options]]
* [[Commonly used debugging tools#Console and startup log output]]


=== Source files ===
=== Source code ===
* {{simgear file|simgear/debug/logstream.cxx}}
* {{simgear file|simgear/debug/logstream.cxx}}
* {{simgear file|simgear/debug/logstream.hxx}}
* {{simgear file|simgear/debug/logstream.hxx}}

Latest revision as of 10:52, 30 January 2024

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