Adds basic logging functionality to Small Basic by using special comments.

sb-logger

Small Basic comes without any logging ability which makes debugging sometimes a painful task. That's why I developed sb-logger.

 

Installation

  1. Download the sb-logger.zip and unpack it.

 

How it works

  1. Add logging statements to your source code (as described below)
  2. Drag & Drop the source file into the sb-logger.exe
  3. Run the generated source file (<source>_with_logging.sb)
  4. </OL>

     

    Logging statements

    Add following statements to your code for logging.

     

    'LOGFILE

    It tells the logging system to write (append) all logging messages to the given file. If this statement is not used, the output is written to the TextWindow.

    Visual Basic
    Edit|Remove
    'LOGFILE Clock.ElapsedMilliseconds + "tetris-log.txt"
    Everything after 'LOGFILE is used in the generated source code in the following way.
    Visual Basic
    Edit|Remove
    _LOG_TO_FILE = Program.Directory + "\"+ Clock.ElapsedMilliseconds + "tetris-log.txt"
     This allows to generate dynamic log-file names.

    'LOG

    It tells sb-logger a message that should be logged.  

    Important: a whitespace have to be between 'LOG and the message.

    Visual Basic
    Edit|Remove
    'LOG "handle key " + GraphicsWindow.LastKey
     Again everything after 'LOG (and a whitespace) is used to create a message. The output of sb-logger for this statement is:
    Visual Basic
    Edit|Remove
    _LOG_SUB = "HandleKey" 
    _LOG_LINE = 89 
    _LOG_MSG = "handle key " + GraphicsWindow.LastKey 
    _LOG()
     It adds the current subroutine ("HandleKey"), the source code line (89) and the message ("handle key " + GraphicsWindow.LastKey). Finally the _LOG() subroutine writes the message.
    To comment a logging statment (so that it is ignored by sb-logger) just add a ' in front of it.
    Visual Basic
    Edit|Remove
    ''LOG "handle key " + GraphicsWindow.LastKey 
    ' also possible 
    '  'LOG "handle key " + GraphicsWindow.LastKey
     
    Example
    Within the sb-logger.zip is tetris.sb. It has already some logging statements.
    Visual Basic
    Edit|Remove
    'LOGFILE Clock.ElapsedMilliseconds + "tetris-log.txt"'LOG "program start" 
    ...
     The first line may already look familiar to you. It tells sb-logger to write the logging messages to the file <EllapsedMilliseconds>tetris-log.txt (see Logging Statements for further explanation). The second line is a logging message.

     
     
    To run the example (with log-file)

    1. Drag&Drop the source file into the sb-logger.exe. A new file with the name tetris_with_logging.sb is created within the folder.
    2. Now open Small Basic, load tetris_with_logging.sb and hit the run button.You will see the familiar Tetris game as without any logging.
    3. Play the game for a while :-)
    4. Go to the folder of tetris_with_logging.sb. There is now a new file called <SomeRandomLookingNumber>tetris-log.txt.
    5. Open it with your editor of choice and you will see all logging messages.
    6. </OL>

       
       To run the example (with TextWindow output)

      1. Remove the first line of tetris.sb
        Visual Basic
        Edit|Remove
        'LOGFILE Clock.ElapsedMilliseconds + "tetris-log.txt"
         
      2. Drag&Drop the source file into the sb-logger.exe. A new file with the name tetris_with_logging.sb is created within the folder.
      3. Now open Small Basic, load tetris_with_logging.sb and hit the run button. You will see the familiar Tetris game and a TextWindow that shows all logging messages.
      4. Play the game for a while :-)
      5. </OL>
        </DIV>
        </DIV></DIV>