LogDispatch�Debug Module

Introduction

Can you imagine the programming process without the possibility of debugging program code at run-time? It is obvious that such programming may exist, but programming without a debugging possibility is too complicated when we are working on big and complex projects. In addition to standard approaches of debugging program code, such as an output window on the Visual Studio IDE or the macros of asserts, I propose a new method for debugging your code: to output your debugging data to the application that is separated from the Visual Studio IDE and the project you are currently working on.

Features

What's so good about it and should I use it?

  • It's a separate module that allows you to trace and debug the release version of your project.
  • It is a fully controlled module with a command set that enables you to control your debugging process: closing tracing windows (also known as trace channel), saving the entry of the trace window to the file, and so forth. Full control set are described below.
  • This module supports several (the number of trace channels is unlimited) strategies of trace channels. A detailed description about trace channel is described below.
  • You can easily modify this module to meet your needs.

Behaviour

Launch the application of trace messages catcher (next: trace catcher) before you start working with this module. Tracing data, sent to the trace catcher application, will be saved if the catcher application was inactive or was terminated during the trace operations. All the data that were saved during the critical situations, as described above, will be kept and popped-out to the trace catcher application when it starts again. There's a possibility to start the trace catcher application with the creation of the trace module and terminate it when the trace module is being destructed.

As I mentioned, this trace module allows you to put your trace data to the several output windows in the trace catcher application (next: trace channels). Trace channel is a simple window that helps to visualize your tracing data by the trace catcher application. To add your trace data to the certain trace channel, you must to describe it as follows:

_Log.setSectionName( "channel_#1" );
_Log.dump( "%s", "My trace data" );

or

_Log.dumpToSection( "channel_#1", "%s", "My trace data" );

If you send your trace data to the new trace channel that is not created in the trace catcher application, a new trace channel will be created automatically.

In addition to sending your trace data to the catcher, there's a possibility to manipulate the trace catcher application with commands help. Commands are divided into two parts: global commands and commands that depend on the trace channel.

Global commands affecting the whole trace catcher application:

  • closeRoot—closing the trace catcher application;
  • onTop.ON—enabling always on top state for the catcher application;
  • onTop.OFF—disabling always on top state for the catcher application.

Example:

_Log.sendCmd( "closeRoot" );
_Log.sendCmd( "onTop.ON")

Commands affecting certain trace channels:

  • clear—deleting the entry of the given trace channel;
  • close—closing the given trace channel;
  • save <path to output stream>—saving the entry of the given trace channel to the output stream that you described.

Example:

_Log.sendCmd( "Channel_1", "clear" );
_Log.sendCmd( "Channel_2", "save c:\\channel2.log" );
_Log.sendCmd( "close" );    /** close the current output window
                              * (section) */

How to Use It

To fully use this trace module, you have to do only two steps:

  • First: You must copy the [LogDispatch.dir] directory from the unzipped source file (LogDispatch_src.zip) to your project directory.
  • Second: You must include the header of this module in your project modules were you want to use it.

Example:

#include "path_by_you\LogDispathc.dir\LogDispath.h"

<ClogDispatch> methods

To call all the messages described below, you must use variable names as follows: [_Log]. The trace object is created once during the project lifetime (using a singleton pattern).

Let's say calling the dump message will be described like this:

_Log.dump( "System time is %d %d %5.5f ", 15, 10, 08.555121 );

Tracing operations

  • dump—Formatted trace data (sprintf format) are sent to catcher application. The tracing data will be placed to the section named as the result of calling the "setSectionName" method before that; or, if the "setSectionName" method wasn't called, tracing data will be placed to the default section named as "output@default".
  • dumpToSection—The principle is the same as dump message. The difference is that this message will place your data to the channel by the name that you described in this message.
  • setSectionName—Set the working (active) channel name.

Configuration command

  • getCmdPrefix—Sets the prefix of the command.
  • setCmdPrefix—Returns the prefix of the command.
  • sendCmd—Sends your message to the receiver application.
  • setCloseOnExit—Enables/disables the possibility to send the message to the catcher application on exit.
  • setCloseCMDOnExit—Sets the command of the catcher application that will be sent when the trace module is destroyed.

Additional operations of the module configuration

  • setClassNameOfCatcher—Sets the class name of the catcher application. That class name will be used in the search of the catcher application where the tracing data will be sent.
  • runCatcher—Executes the catcher application from the described path.

Conclusion

This trace module and the strategy we are using on it is a very flexible and effective trace tool for debugging big projects. In my opinion, this tool will be a very effective strategy to trace release versions of the project where all debugging data are removed. It is very easy and comfortable to use it.



About the Author

Gediminas Siutilas

Born and living in Lithuania. I'm an junior programmer in german software company. I'm a student of Kaunas Tech. University science of informatics. Interessed in programing since the 97's. My general skills are in C/C++, MFC, STL and recently also Java.

Downloads

Comments

  • Window resizing for sidebar debugging on release versions

    Posted by revoscan on 08/04/2005 11:43am

    This is great stuff, just irritatingly always maximizes the windows.
    
    Add:
    /* addition to maximize on creation:revo */
    void CChildFrame::ActivateFrame(int nCmdShow) 
    { 
     if (nCmdShow == -1) 
     { 
      if (IsWindowVisible()) 
      { 
       if (IsIconic()) 
        nCmdShow = SW_RESTORE; 
       else 
        nCmdShow = SW_SHOW; 
      } 
      else 
      { 
       CMDIChildWnd* pChild = GetMDIFrame()->MDIGetActive(); 
       if (!pChild || pChild->IsIconic()) 
        nCmdShow = SW_SHOWMAXIMIZED; 
      } 
     }
     CMDIChildWnd::ActivateFrame(nCmdShow);
    }
    to childform.cpp
    and adjust the class in childform.h
    virtual void CChildFrame::ActivateFrame(int nCmdShow);
    
    
    To adjust the location of the main window frame:
    adjust 
    BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
    {
    	/* change the initial size of the window here */
    	cs.cx=300;
    	cs.cy=600;
    	/* move to left side of the screen */
    	cs.x=GetSystemMetrics (SM_CXSCREEN)-cs.cx;
    	cs.y=GetSystemMetrics (SM_CYSCREEN)-cs.cy;
    
    	if( !CMDIFrameWnd::PreCreateWindow(cs) )
    		return FALSE;
    
    in mainfrm.c
    
    Next adjust 
    void CLogDispatch::runCatcher( const char* strExecutable,
    const char* strPathToExecutalbe )
    {	HINSTANCE mInst;
    	if( !strExecutable )
    		return;
    	mInst=ShellExecute(0, "open" ,strExecutable, NULL,strPathToExecutalbe,SW_SHOWNORMAL);
    }
    in logdispatch.cpp
    
    And you are up for side bar debugging output!
    
    Maybe add tjis to your source with TRACE("..) commands:
    #ifndef _DEBUG
    /* in release we can also debug, declare OPOS_DEBUG */
    #ifdef RELEASE_DEBUG
    #define TRACE              ::_Log.dump
    #else
    #define TRACE              1 ? (void)0 : ::_Log.dump
    #endif
    #endif
    and you can enable or disable release debugging output

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Learn How A Global Entertainment Company Saw a 448% ROI Every business today uses software to manage systems, deliver products, and empower employees to do their jobs. But software inevitably breaks, and when it does, businesses lose money -- in the form of dissatisfied customers, missed SLAs or lost productivity. PagerDuty, an operations performance platform, solves this problem by helping operations engineers and developers more effectively manage and resolve incidents across a company's global operations. …

  • Today's agile organizations pose operations teams with a tremendous challenge: to deploy new releases to production immediately after development and testing is completed. To ensure that applications are deployed successfully, an automatic and transparent process is required. We refer to this process as Zero Touch Deployment™. This white paper reviews two approaches to Zero Touch Deployment--a script-based solution and a release automation platform. The article discusses how each can solve the key …

Most Popular Programming Stories

More for Developers

RSS Feeds