Logging with CodeSite 4

by Radek Červinka 28. December 2010 01:37

Delphi XE including Express version of CodeSite tool.

CodeSite is good tool for logging working on the basis of client - server. During compilation is included client communication code. Communication is performed by sending messages WmCopyData (standard) or with TPC/IP (only full version, but to remote computers too).

Live logging

Basic mode is live logging. First write to "log" start interactive log viewer. This tool accept logged data and display in real time.

For logging add unit CodeSiteLogging and in program write something like this:

  CodeSite.Send( 'When I was younger, so much younger than today');

this is very basic use. There are much more possibilities.

CodeSite.Send

Let's try something more complicated. Consider a VCL application and in OnCreate of form (using the unit CodeSiteLogging):

    1procedure TForm1.FormCreate(Sender: TObject);
    2var
    3  b: TButton;
    4  procedure Vnitrni;
    5  begin
    6    CodeSite.Send( 'Třetí hláška', Self );
    7  end;
    8
    9begin
   10// CodeSiteManager.ConnectUsingCopyData; // default
   11//  CodeSiteManager.ConnectUsingTcp;
   12//  CodeSiteManager.Enabled := False; // disable logging
   13  CodeSite.Send( 'První hláška', Self );
   14  Caption := 'testovací'; // change Caption for demo
   15  CodeSite.Send( 'Druhá hláška', Self );
   16  CodeSite.EnterMethod(Self, 'Vnitrni');
   17  Vnitrni;
   18  CodeSite.ExitMethod(Self, 'Vnitrni'{,Result});
   19
   20
   21  // exception test
   22  b := nil;
   23  try
   24    b.Click;
   25  except
   26    on E:Exception do
   27    begin
   28      CodeSite.SendMsg('Moje poznamka');
   29      CodeSite.SendException(E);
   30    end;
   31  end;
   32end;

In viewer will be this information (detail is enabled when click on magnifier):

CodeSite

Note that when the object parameter IS passing, I allow the display detail of object!

CodeSite

Please note property Caption.

CodeSite

Logging of calling methods with CodeSite.EnterMethod and CodeSite.ExitMethod.

CodeSite

Exception.

Logging to file

Sometimes a live logging is impractical (for example during visiting a client), and instead you appreciate the file, which can be viewed at home.

    1var
    2  Dest: TCodeSiteDestination;
    3
    4begin
    5  Dest := TCodeSiteDestination.Create( Self );
    6
    7  Dest.LogFile.Active := True;
    8  Dest.LogFile.FileName := 'MyFirstLog.csl';
    9  Dest.LogFile.FilePath := '$(MyDocs)';
   10
   11//  Dest.Viewer.Active := True;   // we want LiveView too
   12
   13  CodeSite.Destination := Dest;
   14  CodeSite.Send( 'to file', Sender );

Where $(MyDocs) is alias for Documents. This file can be opened with previous program.

Comments

Remove of logging is possible with conditional compilation or (for disable only) with

  CodeSiteManager.Enabled := False; // disable log

Full version of program can log to remote computer with TCP (CodeSiteManager.ConnectUsingTcp), send a bitmap, screenshots or streams.

Tags: , ,

Tools

Comments are closed