User Tools

Site Tools


dev:logging_and_debugging

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
dev:logging_and_debugging [2014/09/28 08:44] ackleydev:logging_and_debugging [2014/09/28 11:34] (current) ackley
Line 1: Line 1:
 ====== Logging and Debugging ====== ====== Logging and Debugging ======
  
-Here are a few quick tips on getting logging output from the simulator. +Here are a few quick notes on getting logging output from the simulator.
- +
-===== Key concepts =====+
  
   * The simulator has a logging system accessed via the static object ''LOG''.   * The simulator has a logging system accessed via the static object ''LOG''.
-  * The logging system has a 'level' determining how much output is desired.  The level can be set on the command line by the ''-l NUM'' switch, where ''NUM'' can range from 0 (for the least output) to (for the most output).+  * The logging system has a 'level' determining how much output is desired.  The level can be set on the command line by the ''-l NUM'' switch, where ''NUM'' can range from 0 to 8.  ''-l 0'' on the command line produces the least output, ''-l 8'' produces the most.
   * The logging levels have names and numbers: NONE(0), ERROR(1), WARNING(2), MESSAGE(3), DEBUG(4), DEBUG1(5), DEBUG2(6), DEBUG3(7), and ALL(8).    * The logging levels have names and numbers: NONE(0), ERROR(1), WARNING(2), MESSAGE(3), DEBUG(4), DEBUG1(5), DEBUG2(6), DEBUG3(7), and ALL(8). 
-  * The logging code provides direct methods for producing output at levels ERROR, WARNING, MESSAGE, and DEBUG.  For example: <code cpp>LOG.Debug("Hi there");</code> prints 'Hi there' to the console and the logging buffer -- **if** the logging level is 4 or larger. +  * The logging code provides direct methods for producing output at levels ERROR, WARNING, MESSAGE, and DEBUG.  For example: <code cpp>LOG.Debug("Hi there");</code> prints 'Hi there' to the console and the logging buffer (whose display is toggled by 'l' in the GUI) -- **if** the logging level is 4 or larger. 
-  * ''LOG'' offers simple, internally-implemented 'printf-like' functionality.  +  * ''LOG'' offers simple, internally-implemented 'printf-like' functionality.  Among other things, it supports '%d', '%o', '%x', '%s'. Its biggest current limitation is no floating point support (so, no '%f', '%e', or '%g' conversions).  For example:  
 +<code cpp> 
 +  virtual void Behavior(EventWindow<CC>& window) const 
 +  { 
 +    T self = window.GetCenterAtom(); 
 +    LOG.Message("At (%d,%d): type is %04x (%s)", 
 +                window.GetCenterInTile().GetX(), 
 +                window.GetCenterInTile().GetY(), 
 +                self.GetType(), 
 +                "so there"); 
 +                 
 +  } 
 +</code> 
 +might print something like ''20140928032150-3123: At (14,3): type is 00F0 (so there)'' 
 +if the logging level was 3 or higher. 
 +  * Note the logger adds a newline at the end of each log message, so typically it's expected that each log message will be a single line. 
 +  * Use %d for both signed and unsigned ints; there is no '%u' (Or use %x or %o). 
 +  * Grep around in the codebase for 'LOG' to find lots of examples!
dev/logging_and_debugging.1411893897.txt.gz · Last modified: 2014/09/28 08:44 by ackley