Pacific Blue Software Logo

Download the file : PBS Delphi Logger

PBS Delphi Logger


Version 2.0
Downloads : 9

Thread-safe logging system for Delphi with multiple output targets, auto-pruning and severity tracking.



Free Delphi source code for a lightweight, thread-safe logger that writes to files, the console and VCL memos at the same time, from anywhere in your application. It uses a singleton, so there is no logger instance to create or pass around - add the outputs you want once at startup, then call TLogger.Write from any unit or thread.

Why use it

  • Drop-in logging for VCL applications, console tools, Windows services and background threads
  • One call writes to every output - a daily log file for the record, a memo on screen while debugging, the console for command line tools
  • Log files rotate daily and old ones are pruned automatically, so a long-running service never fills the disk
  • Files are closed after a few seconds of inactivity, so logs can be read, copied or deleted while the application is still running
  • Exceptions are written as formatted error blocks with class and method context, and the last severe exception is kept for watchdog checks
  • Small and readable - seven short units, no packages to install and no third-party dependencies

What is in the download

  • PBS.LIB.Log - the TLogger singleton and the TLog_Output base class
  • PBS.LIB.Log.Disk - daily rotating file output with pruning and an On_Error hook
  • PBS.LIB.Log.Console - console output
  • PBS.LIB.Log.Memo - TMemo output for live display on a form
  • PBS.LIB.Prune_Files - removes old log files, keeping the most recent
  • PBS.LIB.CmdLine and PBS.LIB.Common - helpers used by the file output
Full source code is included, with usage documentation in the units.

Quick start

Add the units to your project or search path, register the outputs at startup, then log:
uses
  PBS.LIB.Log, PBS.LIB.Log.Disk;

TLogger.Add_Output (TFile_Log_Output.Create ('', 'MyApp'));
TLogger.Write ('Application started');
TLogger.Write ('Order Total', 42);
With an empty path the log files go to a logs folder next to the executable, one file per day, named MyApp_YYYYMMDD.log. The article linked below covers every option, the memo output, multiple log files and writing your own output class.

Requirements

  • Delphi XE7 or later (uses generics)
  • Windows - VCL is needed only for the memo output

Version 2.0

Adds automatic log file pruning, an On_Error hook for the file output, Write overloads for string, boolean and integer values against a label, and a Last_Severe property. Several file outputs can be active at once, eg. a main log and a separate error log. TLogger.Write no longer takes an ATime parameter; timestamps are controlled with the Include_TimeStamp property.

Read the article : PBS Delphi Logger - Thread-safe logging with multiple outputs

Free to use and modify


These links expire in one hour. Refresh the screen to extend the time.

Windows


Windows