Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Catalog · How the catalog works

Random project

MTLogger

Multi-threaded safe, crossplatform logger for Lazarus/FPC and Delphi.

View on GitHub

Anyone may press Interesting, signed in or not. It helps others find this project.

Member rating

No ratings yet.

Sign in to rate this project.

README

MTLogger — thread-safe, cross-platform Logger for Lazarus/FPC and Delphi

MTLogger is a thread-safe, cross-platform logger for Lazarus/FPC and Delphi.
It supports asynchronous file logging, real-time log capture, and optional immediate console output.
MTLogger is implemented as a singleton, so no manual initialization is required.


Quickstart

  1. Download u_logger.pas or install MTLogger using the boss install command:
bash
boss install https://github.com/kompustelnik/MTLogger
  1. Add u_logger to the uses section:
pascal
uses
  u_logger;
  1. (OPTIONALLY) Assign OnLogEventProc (for global procedures) or OnLogEventObj (e.g. for class methods) to catch logs real-time.
pascal
procedure TForm1.FormCreate(Sender: TObject);
begin
  MTLogger.OnLogEventObj:= CatchLog;
  MTLogger.Log('Starting application.');
end;

procedure TForm1.CatchLog(const AMessage: String);
begin
  Memo1.Lines.Add(AMessage);
end;

With this setup, any log message generated via Log, LogWarning, or LogError can be captured in real-time.

  1. Start logging:
  • Info log:
pascal
MTLogger.Log('Hello, World!');
  • Warning log:
pascal
MTLogger.LogWarning('Settings file modified');
  • Error log:
pascal
MTLogger.LogError('Exception message: ' + E.Message);

Logging directly to the console

In console applications, you can print a log message immediately:

pascal
WriteLn(MTLogger.Log('Starting application'));

Example output:

pascal
2026-01-25 22:01:29 - INFO - Starting application.

Sample log file

pascal
2026-01-25 21:22:29 - INFO - Starting application.
2026-01-25 21:22:37 - INFO - Button 1 pressed
2026-01-25 21:22:38 - INFO - Checkbox 1 checked
2026-01-25 21:22:38 - INFO - Checkbox 2 checked
2026-01-25 21:22:49 - WARNING - Button 2 pressed
2026-01-25 21:22:49 - ERROR - Button 3 pressed
2026-01-25 21:22:50 - INFO - Button 1 pressed
2026-01-25 21:22:50 - INFO - Button 1 pressed
2026-01-25 21:22:51 - INFO - Closing application.

Features

  • Cross-platform support: Windows, Linux, macOS
  • Supports real-time capture via OnLogEventProc/OnLogEventObj
  • Can log INFO, WARNING, and ERROR levels
  • Safe shutdown, ensuring no log messages are lost
  • Optional immediate console output for console apps