User Tools

Site Tools


dev:logging_and_debugging

Logging and Debugging

Here are a few quick notes on getting logging output from the simulator.

  • 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 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 code provides direct methods for producing output at levels ERROR, WARNING, MESSAGE, and DEBUG. For example:
    LOG.Debug("Hi there");

    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. 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:
  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");
 
  }

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.txt · Last modified: 2014/09/28 11:34 by ackley