Powerful and flexible library for logging on files, console, memory, email, rest, eventlog, syslog, slack, telegram, redis, logstash, elasticsearch, influxdb, graylog, Sentry, Twilio, ide debug messages and throw events for Delphi/Firemonkey/freepascal/.NET (Windows/Linux/OSX/IOS/Android).
Delphi(Delphi XE6 - Delphi 12 Athens)/Freepascal(trunk)/.NET (Windows/Linux/Android/MACOSX/IOS) library for logging on multi providers:
Please "star" this project in GitHub! It costs nothing but helps to reference the code.
If you find this project useful, please consider making a donation.
Feb 10,2024 RAD Studio 12 supported
Nov 22,2021 RAD Studio 11 supported
May 30,2020: RAD Studio 10.4 supported
May 02,2020: Twilio provider
Apr 25,2020: Custom Output Format & custom Tags support
Apr 24,2020: Sentry provider
Sep 14,2019: New optional Included log info: ThreadId.
Sep 11,2019: Now included on RAD Studio GetIt package manager.
Mar 28,2019: Unhandled exceptions hook
Mar 28,2019: Improved exception info
Mar 16,2019: GrayLog provider
Feb 28,2019: InfluxDB provider
Feb 26,2019: ElasticSearch provider
Feb 25,2019: Logstash provider
Feb 19,2019: Delphi Linux compatilibity.
Feb 10,2019: Firemonkey OSX & IOS compatibility.
Dec 08,2018: Load/Save providers config from single json
Dec 07,2018: Delphi 10.3 Rio support
Sep 11,2018: Firemonkey android compatibility improved
Jul 04,2018: Native dll and .Net warpper (thanks to Turrican)
Jun 29,2018: Config from/to Json
Jun 15,2018: SysLog provider.
May 28,2018: Slack provider.
May 27,2018: ADODB provider.
May 27,2018: Telegram provider.
May 25,2018: Custom output Msg.
May 22,2018: ELK support.
May 20,2018: Delphinus support.
May 20,2018: Json output with optional fields for Redis and Rest providers.
May 17,2018: FreePascal Linux compatibility.
May 02,2018: FreePascal Windows compatibility.
Quick Logger is asynchronous. All logs are sent to a queue and don't compromises your application flow. You can define many providers to sent every log entry and decide what level accepts every one.
program
{$APPTYPE CONSOLE}
uses
Quick.Logger:
Quick.Logger.Provider.Files;
Quick.Logger.Provider.Console;
begin
//Add Log File and console providers
Logger.Providers.Add(GlobalLogFileProvider);
Logger.Providers.Add(GlobalLogConsoleProvider);
//Configure provider options
with GlobalLogFileProvider do
begin
FileName := '.\Logger.log';
DailyRotate := True;
MaxFileSizeInMB := 20;
LogLevel := LOG_ALL;
Enabled := True;
end;
with GlobalLogConsoleProvider do
begin
LogLevel := LOG_DEBUG;
ShowEventColors := True;
Enabled := True;
end;
Log('Test entry',etInfo);
Log('Test number: %d',[1],etWarning);
end.
QuickLogger manages Logger and Providers automatically. Logger and providers have a global class, auto created and released on close your app. You only need to add wanted providers to your uses clause.
Note: You need to add almost one provider to send logging.
Properties:
- **Providers:** List of providers to send logs.
- **OnProviderError:** Event to receive provider error notifications.
- **RedirectOwnErrorsToProvider:** Select provider to get all provider notification errors.
- **WaitForFlushBeforeExit:** Number of seconds logger allowed to flush queue before closed.
- **QueueCount:** Queued items in main queue.
- **ProvidersQueueCount:** Queued items in providers queue (all providers).
- **OnQueueError:** Event for receive queue errors.
- **IsQueueEmpty:** Check if main queue or any provider queue has items pending to process.
There are a range of eventtypes you can define in your logs: etHeader, etInfo, etSuccess, etWarning, etError, etCritical, etException, etDebug, etTrace, etCustom1, etCustom2.
Every logger provider can be configured to listen for one or more of these event types and limit the number of received eventtypes received for a range of eventtypes per Day, hour, minute or second for avoid performance problems or be spammed.
Providers manage the output for your logs. Output can be file, console, email, etc. If a provider fails many times to send a log, will be disabled automatically (full disk, remote server down, etc). Limits can be specified per provider. Providers have a property to change Time format settings property to your needs. Every provider has a queue log to receive log items, but can be disabled to allow direct write/send. There are some events to control providers work (OnRestart, OnCriticalError, OnSendLimits, etc).
There are some predefined providers, but you can make your own provider if needed:
FILE PROVIDER:
Quick.Logger.Provider.Files: Sends logging to a file, managing log rotation and compression.
Properties:
CONSOLE PROVIDER:
Quick.Logger.Provider.Console: Sends logging to console out, allowing colored eventypes and timestamp.
Properties:
EMAIL PROVIDER:
Quick.Logger.Provider.Email: Sends logging by email.
Properties:
EVENTS PROVIDER:
Quick.Logger.Provider.Events: Allows throw an event for every log item received.
Properties:
IDE DEBUG PROVIDER:
Quick.Logger.Provider.IDEDebug: Sends Logging to IDE Debug messages.
Properties:
WINDOWS EVENTLOG PROVIDER:
Quick.Logger.Provider.EventLog: Sends Logging to Windows EventLog.
Properties:
HTTP REST PROVIDER:
Quick.Logger.Provider.Rest: Sends Logging to Restserver as a JSON post.
Properties:
REDIS PROVIDER:
Quick.Logger.Provider.Redis: Sends Logging to Redis server.
Properties:
MEMORY PROVIDER:
Quick.Logger.Provider.Memory: Saves logging into memory.
Properties:
TELEGRAM PROVIDER:
Quick.Logger.Provider.Telegram: Send log as a message to public/private Telegram channel. (You need token of a bot in this channel)
Properties:
SLACK PROVIDER:
Quick.Logger.Provider.Slack: Send log as a message to public/private Slack channel.
Properties:
ADODB PROVIDER:
Quick.Logger.Provider.ADODB: Saves log to ADO database (MSSQL, MSAccess, etc..)
Properties:
SYSLOG PROVIDER:
Quick.Logger.Provider.SysLog: Sends Logging to SysLog server.
Properties:
LOGSTASH PROVIDER:
Quick.Logger.Provider.Logstash: Sends Logging to Logstash service.
Properties:
ELASTICSEARCH PROVIDER:
Quick.Logger.Provider.ElasticSearch: Sends Logging to ElasticSearch server.
Properties:
INFLUXDB PROVIDER:
Quick.Logger.Provider.InfluxDB: Sends Logging to InfluxDB Database.
Properties:
GRAYLOG PROVIDER:
Quick.Logger.Provider.GrayLog: Sends Logging to GrayLog service.
Properties:
SENTRY PROVIDER:
Quick.Logger.Provider.Sentry: Sends Logging to Sentry service.
Properties:
TWILIO PROVIDER:
Quick.Logger.Provider.Twilio: Sends Logging to Twilio service.
Properties:
QuickLogger allows to select what info to log. You can include HOSTNAME, OS Version, AppName, Platform or Environment(production, test, etc), ThreadId, ProcessId and other fields (to be compatible with multienvironments or multidevices). It's more evident for a remote logging like redis or rest, but File provider can be write a header with this fields if you like.
Properties:
GlobalLogConsoleProvider.IncludedInfo := [iiAppName,iiHost,iiEnvironment,iiPlatform];
GlobalLogConsoleProvider.IncludedTags := ['MyTag1','MyTag2'];
GlobalLogRedisProvider.CustomMsgOutput := True;
Log('{"level":"warn","text":"my text"}',etInfo);
GlobalLogConsoleProvider.CustomMsgOutput := True;
GlobalLogConsoleProvider.CustomFormatOutput := '%{DATE} & %{TIME} - [%{LEVEL}] : %{MESSAGE} (%{MYTAG1})';
QuickLogger has a lot of predefined variables, but you can define your own tags to use into custom output format.
DATETIME : Date & time log item occurs
DATE : Date log item occurs
TIME : Time log item occurs
LEVEL : Level or Eventype
LEVELINT : Level as numeric
MESSAGE : Message sent to logger
ENVIRONMENT : Customizable variable (normally Production, Test, etc)
PLATFORM : Customizable variable (normally Desktop, Mobile, etc)
APPNAME : Customizable variable (by default set as filename without extension)
APPVERSION : Application file version
APPPATH : Application run path
HOSTNAME : Computer name
USERNAME : Logged user name
OSVERSION : OS version
CPUCORES : Number of CPU cores
THREAID : Thread Id log item set
Logger.LogTags['MODULE'] := 'Admin';
GlobalLogConsoleProvider.CustomMsgOutput := True;
GlobalLogConsoleProvider.CustomFormatOutput := '%{DATE} & %{TIME} - [%{LEVEL}] : %{MESSAGE} (%{MODULE})';
QuickLogger can import or export config from/to JSON format. This feature allows a easy way to preconfigure your providers.
//Load single provider from json file
GlobalLogRedisProvider.LoadFromFile('C:\logfileprovider.json');
//Save all providers to json file
Logger.Providers.SaveToFile('C:\loggerconfig.json');
//Load all providers from json string
Logger.Providers.FromJson(json);
Example multiprovider config file:
{"GlobalLogConsoleProvider":
{
"ShowEventColors": true,
"ShowTimeStamp": true,
"UnderlineHeaderEventType": false,
"Name": "TLogConsoleProvider",
"LogLevel": "[etHeader,etInfo,etSuccess,etWarning,etError,etCritical,etException,etDone,etCustom1,etCustom2]",
"TimePrecission": true,
"MaxFailsToRestart": 2,
"MaxFailsToStop": 10,
"CustomMsgOutput": false,
"UsesQueue": true,
"Enabled": true,
"SendLimits": {
"TimeRange": "slNoLimit",
"LimitEventTypes": "[]",
"MaxSent": 0
},
"AppName": "QuickLoggerDemo",
"Environment": "",
"PlatformInfo": "",
"IncludedInfo": "[iiAppName,iiHost]"
},
"GlobalLogFileProvider":
{
"FileName": "D:\\LoggerDemo.log",
"AutoFileNameByProcess": false,
"MaxRotateFiles": 3,
"MaxFileSizeInMB": 10,
"DailyRotate": false,
"RotatedFilesPath": "",
"CompressRotatedFiles": false,
"ShowEventType": true,
"ShowHeaderInfo": true,
"UnderlineHeaderEventType": false,
"AutoFlush": false,
"Name": "TLogFileProvider",
"LogLevel": "[etInfo,etSuccess,etWarning,etError,etCritical,etException]",
"TimePrecission": false,
"MaxFailsToRestart": 2,
"MaxFailsToStop": 10,
"CustomMsgOutput": false,
"UsesQueue": true,
"Enabled": true,
"SendLimits": {
"TimeRange": "slNoLimit",
"LimitEventTypes": "[etInfo]",
"MaxSent": 0
},
"AppName": "QuickLoggerDemo",
"Environment": "",
"PlatformInfo": "",
"IncludedInfo": "[iiAppName,iiHost,iiUserName,iiOSVersion]"
}
}
QuickLogger can capture your application exceptions. There are 3 exception hooks. You need to add one or more units to your uses clause:
Do you want to learn delphi or improve your skills? learndelphi.org