Wiki copymirror

This is a mirror of the wiki at pascal.chat. Editing, history and sign-in are there.

MultiLog

About

MultiLog is a log system that aims at flexibility and low overhead at the same time. As the name suggests, it can be used to log to several targets such as a text file, a visual control or to another application. Adding new targets is as easy as creating a class that implements two methods, one being optional.

MultiLog is in general similar to CodeSite, Smart Inspect, Overseer and EstLogger but it does not follow closely any of them, implementing many things differently and, even, having some unique features.

Starting from version 0.5, the base library can be compiled with Delphi.

Features:

Here's the provided Log Viewer in action:

Author

Luiz Américo Pereira Câmara aka Karl Brandt

Contact: pascalive at bol(dot)com(dot)br

License

Modified LGPL

Download

MultiLog library and MultiLogViewer: https://github.com/blikblum/multilog

Change Log

System Requirements

Usage

Simple example

Install multiloglaz package into Lazarus and build MultiLogViewer from it's Viewer directory. Create new application, and add 4 buttons, 1 spinedit, and 1 panel to main form. Replace code with the one below. Start MultiLogViewer, run your application and logging will start. Since we have added both ipc and file channels for logging (in Form's OnCreate method), even if MultiLogViewer is not started we will have logging to 'debug.log' file.

pascal
unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
  Spin, ExtCtrls, MultiLog {must be included for Multilog logging},
  ipcchannel  {logging over IPC channel to MultiLog Viewer application},
  filechannel {logging over file channel to log file};

type

  { TForm1 }

  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    Panel1: TPanel;
    SpinEdit1: TSpinEdit;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure Panel1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    procedure Panel1MouseEnter(Sender: TObject);
    procedure Panel1MouseLeave(Sender: TObject);
    procedure Panel1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    procedure SpinEdit1Change(Sender: TObject);
  private

  public

  end;

var
  Form1: TForm1;

implementation

{$R *.lfm}

{ TForm1 }

procedure TForm1.FormCreate(Sender: TObject);
begin
  Logger.Channels.Add(TFileChannel.Create('debug.log')); // switch on file logging
  Logger.Channels.Add(TIPCChannel.Create); // switch on ipc logging
  Logger.Send('----------------------------------------------------');
  Logger.Send('Form1 created');
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  Logger.Send('Form1 destroyed');
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Logger.IncCounter('MyLogCounter');
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  Logger.ResetCounter('MyLogCounter');
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  Logger.Watch('MyLogWatch', Caption);
end;

procedure TForm1.Button4Click(Sender: TObject);
var
  Exc: EMathError;
begin
  try
    Exc := EMathError.Create('fake math exception');
    raise Exc;
  except
    on E: Exception do Logger.SendException('Exception: Force fake math exception', E);
  end;
end;

procedure TForm1.Panel1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  Logger.Send('Panel1MouseDown');
end;

procedure TForm1.Panel1MouseEnter(Sender: TObject);
begin
  Logger.Send('Panel1MouseEnter');
end;

procedure TForm1.Panel1MouseLeave(Sender: TObject);
begin
  Logger.Send('Panel1MouseLeave');
end;

procedure TForm1.Panel1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  Logger.Send('Panel1MouseUp');
end;

procedure TForm1.SpinEdit1Change(Sender: TObject);
begin
  Logger.EnterMethod('SpinEdit1Change');
  try
    Caption := 'New SpinEdit1 value is ' + IntToStr(SpinEdit1.Value);
    Logger.Send('SpinEdit1.Value', SpinEdit1.Value);
  finally // we want to make sure that each EnterMethod is paired with it's Exitmethod
    Logger.ExitMethod('SpinEdit1Change');
  end;
end;

end.

This is how the result should look like in runtime (if you replace default captions as shown):

If you want your logged exceptions and stacks to show source code line numbers of the runtime error like on the screenshot above then go to Project / Project Options / Compiler Options / Debugging and switch on check boxes for 'Generate debugging info for GDB' and 'Display line numbers in run-time error backtraces'.

Known Issues

See also


From the Free Pascal wiki, page "MultiLog", as it stood on 2021-10-25 after a change by Kai Burghardt, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.

Revision 2, last changed by WikiArchive .