Note
SimpleLog-FP is currently in active development. This is a pre-1.0 release (v0.5.1). The API may change and feedback is welcome!
A simple, lightweight, and easy-to-use logging library for Free Pascal applications.
Why SimpleLog-FP? π€ Built from the need for a logging library that is actually simple to use and maintain. No feature bloat, no complexity - just clean, reliable logging for console, file, or both.
- β Simple - Easy for new developers to understand and use
- β Lightweight - ~415 lines of code, no bloat
- β Maintainable - Clean code and easily maintainable
- β Focused - Does three things well: console, file, and console+file logging
- β No dependencies - Uses only standard Free Pascal units
- β Cross-platform - Works on Windows and Unix systems
- β File rotation - Automatic log file rotation when size limits are reached
From GitHub:
git clone https://github.com/ikelaiah/simplelog-fp.git
cd simplelog-fp
Manual Installation:
- Download
src/SimpleLog.pas
from this repository - Copy it to your project directory
- Add
SimpleLog
to your uses clause - Start logging!
uses SimpleLog;
var
Log: TSimpleLog;
begin
// Console only
Log := TSimpleLog.Console;
Log.Info('Hello World!');
// File only
Log := TSimpleLog.FileLog('app.log');
Log.Info('Logged to file');
// Both console and file
Log := TSimpleLog.Both('app.log');
Log.Info('Appears in both console and file');
end;
That's it! No complex setup, no memory management, no configuration files required.
- 5 log levels: Debug, Info, Warning, Error, Fatal
- Timestamped messages: Each log entry includes precise timestamp with milliseconds
- Colored console output with appropriate colors per level
- File logging with automatic directory creation
- Dual output to both console and file simultaneously
- Format string support for all log methods
- Thread safety - protected by critical sections for multi-threaded applications
- Silent mode to temporarily disable all logging output
All log messages follow a consistent, readable format:
[2025-07-01 14:30:22.123] [INFO] Application started
[2025-07-01 14:30:22.456] [WARNING] Low disk space: 15.5% remaining
[2025-07-01 14:30:22.789] [ERROR] Database connection failed
[2025-07-01 14:30:23.012] [DEBUG] User authentication successful
[2025-07-01 14:30:23.345] [FATAL] Critical system error
Timestamp format: yyyy-mm-dd hh:nn:ss.zzz
- ISO 8601 compatible date format (sortable)
- 24-hour time format
- Millisecond precision for performance analysis
- Consistent across console and file output
- Method chaining for fluent configuration
- Log level filtering - set minimum level to reduce noise
- File rotation - automatic rotation when files exceed size limit
- Custom file paths with automatic directory creation
- Windows: Console colors via Windows API
- Unix/Linux: Console colors via ANSI escape codes
- Consistent behavior across platforms
TSimpleLog.Console // Console output only
TSimpleLog.FileLog('file.log') // File output only
TSimpleLog.Both('file.log') // Both console and file
Log.Debug('Debug message');
Log.Info('Information');
Log.Warning('Warning message');
Log.Error('Error occurred');
Log.Fatal('Critical error');
// Format string variants
Log.Info('User %s has %d items', [username, count]);
Log.Error('Connection failed: %s:%d', [host, port]);
Log := TSimpleLog.Console
.SetMinLevel(llWarning) // Only warnings and above
.SetOutputs([odConsole, odFile]) // Enable both outputs
.SetFile('app.log') // Set log file
.SetMaxFileSize(5 * 1024 * 1024) // 5MB rotation limit
.SetSilent(False); // Enable/disable all logging
Log.Outputs := [odConsole, odFile]; // Set output destinations
Log.LogFile := 'myapp.log'; // Set log file path
Log.MinLevel := llInfo; // Set minimum log level
Log.MaxFileSize := 10 * 1024 * 1024; // Set rotation size (10MB)
Log.Silent := True; // Enable/disable silent mode
program MyApplication;
uses SimpleLog;
var
Log: TSimpleLog;
UserCount: Integer;
begin
// Initialize logging to both console and file
Log := TSimpleLog.Both('application.log')
.SetMinLevel(llInfo); // Hide debug messages in production
Log.Info('Application starting up');
try
// Your application logic
UserCount := LoadUsers();
Log.Info('Loaded %d users from database', [UserCount]);
if UserCount = 0 then
Log.Warning('No users found in database');
except
on E: Exception do
begin
Log.Error('Startup failed: %s', [E.Message]);
ExitCode := 1;
Exit;
end;
end;
Log.Info('Application ready');
// Your main application loop here...
Log.Info('Application shutting down');
end;
// Production: Only show warnings and errors
Log := TSimpleLog.Both('prod.log').SetMinLevel(llWarning);
// Development: Show everything including debug
Log := TSimpleLog.Console.SetMinLevel(llDebug);
// Rotate when file exceeds 1MB
Log := TSimpleLog.FileLog('big.log').SetMaxFileSize(1024 * 1024);
Log.Info('This will rotate when file gets too big');
// Temporarily disable all logging
Log.SetSilent(True);
Log.Error('This error will not appear anywhere');
// Re-enable logging
Log.SetSilent(False);
Log.Info('Logging is back on');
// SimpleLog is thread-safe by default!
// All logging operations are protected by a critical section.
// You can safely use the same logger instance from multiple threads.
var
Log: TSimpleLog;
begin
Log := TSimpleLog.Both('threaded.log');
// Use Log from multiple threads with confidence
Log.Info('Multi-threaded logging works reliably');
end;
SimpleLog uses Free Pascal's advanced records instead of classes:
- β No memory management - no Create/Free needed
- β Stack allocated - automatic cleanup
- β Lightweight - minimal overhead
- β Value semantics - can be copied safely
- β Modern Pascal - leverages language features
SimpleLog-FP/
βββ src/
β βββ SimpleLog.pas # Main library (~415 lines)
βββ examples/
β βββ SimpleLogExample/ # Basic usage examples
β βββ ThreadSafeExample/ # Concurrent logging demo
βββ tests/
β βββ SimpleLog.Test.pas # Comprehensive test suite
βββ docs/
β βββ SimpleLogger.md # User manual
β βββ cheat-sheet.md # Quick API reference
βββ README.md # This file
A comprehensive test suite is provided in the tests/
directory. To run the tests:
- Open
TestRunner.lpi
in the Lazarus IDE or uselazbuild
(required) - Build and run the project to execute all tests
- Review the output in the IDE or generated log files
A ready-to-use Lazarus package is included for easy integration:
- Open
packages/lazarus/simplelog.lpk
in the Lazarus IDE - Click "Use" β "Add to Project" to add SimpleLog-FP to your project
- The package will automatically add the correct search paths
This is the recommended way to add SimpleLog-FP to your Lazarus projects for the best experience.
Feature | SimpleLog-FP | Complex Logger |
---|---|---|
Lines of code | ~415 | 2000+ |
Learning curve | Minutes | Hours |
Features | 3 core outputs | 20+ features |
Maintenance | Easy | Complex |
Memory usage | Minimal | Higher |
Dependencies | None | Multiple |
Keep it simple! Any contributions should maintain the core philosophy:
- No feature bloat
- Easy to understand
- Focused on core logging needs
MIT License - see LICENSE file for details.
- Free Pascal Dev Team for the Pascal compiler
- Lazarus IDE Team for such an amazing IDE
- The kind and helpful individuals on various online platforms such as:
- Unofficial Free Pascal discord server
- Free Pascal & Lazarus forum
- Tweaking4All Delphi, Lazarus, Free Pascal forum
- Laz Planet - Blogspot / Laz Planet - GitLab
- Delphi Basics
- @gcarreno for various suggestions and improvements
- All contributors who have helped improve this project