Skip to content
Delphi/freepascal/.NET (Windows/Linux/OSX/IOS/Android) library for logging on files, console, memory, email, rest, eventlog, syslog, slack, telegram, redis, logstash, elasticsearch, influxdb, graylog, ide debug messages and throw events.
Branch: master
Clone or download
Latest commit 7007384 Apr 11, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.vscode .NET to Native string fix. Now wrapper is stable Mar 26, 2019
library Fixed callbackOnCollectedDelegate exception when provider has errors Apr 3, 2019
samples delphi samples updated Mar 16, 2019
.gitignore gitignore updated Feb 24, 2019
Delphinus.Info.json Delphinus support May 20, 2018
Delphinus.Install.json delphinus install fixed Dec 9, 2018
LICENSE.txt First commit Jan 21, 2018
Quick.Logger.ExceptionHook.pas small changes Mar 28, 2019
Quick.Logger.Provider.ADODB.pas ADODB provider May 29, 2018
Quick.Logger.Provider.Console.pas Custom output and small refactory May 24, 2018
Quick.Logger.Provider.ElasticSearch.pas New ElasticSearch provider Feb 25, 2019
Quick.Logger.Provider.Email.pas compatibility with Json serializer Jul 3, 2018
Quick.Logger.Provider.EventLog.pas Firemonkey OSX, IOS & Delphi Linux compatibility Feb 19, 2019
Quick.Logger.Provider.Events.pas Custom output and small refactory May 24, 2018
Quick.Logger.Provider.Files.pas File provider restart after filename changes Mar 25, 2019
Quick.Logger.Provider.GrayLog.pas GrayLog provider control timeout options Mar 25, 2019
Quick.Logger.Provider.IDEDebug.pas Firemonkey OSX, IOS & Delphi Linux compatibility Feb 19, 2019
Quick.Logger.Provider.InfluxDB.pas New InfluxDB provider Feb 28, 2019
Quick.Logger.Provider.Logstash.pas New Logstash provider Feb 25, 2019
Quick.Logger.Provider.Memory.pas Firemonkey OSX, IOS & Delphi Linux compatibility Feb 19, 2019
Quick.Logger.Provider.Redis.pas Redis provider added KeepAlive and Timeout options Apr 5, 2019
Quick.Logger.Provider.Rest.pas Rest provider improved Feb 24, 2019
Quick.Logger.Provider.Slack.pas Slack Provider May 29, 2018
Quick.Logger.Provider.SysLog.pas native Library updated .NET Library Wrapper update Nov 14, 2018
Quick.Logger.Provider.Telegram.pas Telegram provider May 29, 2018
Quick.Logger.RuntimeErrorHook.pas New RuntimeError Hook Mar 28, 2019
Quick.Logger.UnhandledExceptionHook.pas fpc compatibility fix Apr 9, 2019
Quick.Logger.pas option JsonOutputOptions.TimestampName to allow change field name Apr 11, 2019
QuickLib.inc inc updated Feb 28, 2019
QuickLogger.png Delphinus support May 20, 2018
README.md readme updated Mar 28, 2019

README.md

QuickLogger


Delphi(Delphi XE6 - Delphi 10.3.1 Rio)/Freepascal(trunk)/.NET (Windows/Linux/Android/MACOSX/IOS) library for logging on multi providers:

  • Files
  • Console
  • Memory
  • Email
  • Rest server
  • Windows EventLog
  • Redis server
  • IDE debug
  • Throw events
  • Telegram
  • Slack
  • MSSQL, MSAcces, etc with ADODB.
  • SysLog
  • Logstash
  • ElasticSearch
  • InfluxDB
  • GrayLog
  • Controlled and unhandled exceptions hook

Updates:

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.

Logger:

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.

EventTypes:

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:

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:

  • Quick.Logger.Provider.Files: Sends logging to a file, managing log rotation and compression.

    Properties:

    • Filename: Filename of your log file. If not defined, gets name of your program + log
    • LogLevel: Log level that your provider accepts.
    • EventTypeNames: Every eventtype has a customizable text you can change to be reflected in your logs.
    • SendLimits: Defines max number of logs entries sent by day, hour, minute or second to avoid be spammed. Can be configured to limit only certain event types.
    • ShowEventType: Shows eventype (WARN, ERROR, INFO,..)
    • ShowHeaderInfo: Every execution or new log file logs a header with system information like Username, CPU, path, debug mode, etc.
    • UnderlineHeaderEventType: Writes an underline below every etHeader eventtype.
    • TimePrecission: If true, shows date and time and milliseconds in log entries.
    • DailyRotate: Rotates log file every day.
    • MaxFileSizeInMB: If value is greater than 0, rotates log file by size. It's independent of dailyrotate option.
    • MaxRotateFiles: Max number of files to keep when rotate a log.
    • RotatedFilesPath: Path where rotated files will be moved/zipped. If leave blank, rotated files will be remain in same folder log exists.
    • CompressRotatedFiles: Defines if rotated files will be compressed.
    • Enabled: Enables/disables receive logging.
  • Quick.Logger.Provider.Console: Sends logging to console out, allowing colored eventypes and timestamp.

    Properties:

    • ShowEventColors: Enables colored Event types when writes to console. There are predefined colors but you can change every eventype color with EventTypeColor property (EventTypeColor[etInfo] := clBlue)
    • LogLevel: Log level that your provider accepts.
    • EventTypeNames: Every eventtype has a customizable text you can change to be reflected in your logs.
    • SendLimits: Defines max number of logs entries sent by day, hour, minute or second to avoid be spammed. Can be configured to limit only certain event types.
    • ShowEventType: Shows eventype (WARN, ERROR, INFO,..).
    • UnderlineHeaderEventType: Writes an underline below every etHeader eventtype.
    • ShowTimeStamp: Shows datetime for every log entry.
    • TimePrecission: If true, shows date and time and milliseconds in log entries.
    • Enabled: Enables/disables receive logging.
  • Quick.Logger.Provider.Email: Sends logging by email.

    Properties:

    • SMTP: Class to define host and email account info.
    • LogLevel: Log level that your provider accepts.
    • EventTypeNames: Every eventtype has a customizable text you can change to be reflected in your logs.
    • SendLimits: Defines max number of emails sent by day, hour, minute or second to avoid be spammed. Can be configured to limit only certain event types.
    • ShowTimeStamp: Shows datetime for every log entry.
    • TimePrecission: If true, shows date and time and milliseconds in log entries.
    • Enabled: Enables/disables receive logging.
  • Quick.Logger.Provider.Events: Allows throw an event for every log item received.

    Properties:

    • LogLevel: Log level that your provider accepts.
    • EventTypeNames: Every eventtype has a customizable text you can change to be reflected in your logs.
    • SendLimits: Defines max number of emails sent by day, hour, minute or second.
    • TimePrecission: If true, shows date and time and milliseconds in log entries.
    • OnInfo..OnError and OnAny: Events thown for every event type.
    • Enabled: Enables/disables receive logging.
  • Quick.Logger.Provider.IDEDebug: Sends Logging to IDE Debug messages.

    Properties:

    • LogLevel: Log level that your provider accepts.
    • EventTypeNames: Every eventtype has a customizable text you can change to be reflected in your logs.
    • SendLimits: Defines max number of emails sent by day, hour, minute or second.
    • TimePrecission: If true, shows date and time and milliseconds in log entries.
    • Enabled: Enables/disables receive logging. Provider begins to receive logs after enabled.
  • Quick.Logger.Provider.EventLog: Sends Logging to Windows EventLog.

    Properties:

    • LogLevel: Log level that your provider accepts.
    • EventTypeNames: Every eventtype has a customizable text you can change to be reflected in your logs.
    • SendLimits: Defines max number of emails sent by day, hour, minute or second.
    • TimePrecission: If true, shows date and time and milliseconds in log entries.
    • Source: Name of source shown in eventlog.
    • Enabled: Enables/disables receive logging.
  • Quick.Logger.Provider.Rest: Sends Logging to Restserver as a JSON post.

    Properties:

    • LogLevel: Log level that your provider accepts.
    • EventTypeNames: Every eventtype has a customizable text you can change to be reflected in your logs.
    • SendLimits: Defines max number of emails sent by day, hour, minute or second.
    • TimePrecission: If true, shows date and time and milliseconds in log entries.
    • UserAgent: Useragent string.
    • URL: URL to send post json.
    • JsonOutputOptions: Json options to format output json.
    • Enabled: Enables/disables receive logging.
  • Quick.Logger.Provider.Redis: Sends Logging to Redis server.

    Properties:

    • LogLevel: Log level that your provider accepts.
    • EventTypeNames: Every eventtype has a customizable text you can change to be reflected in your logs.
    • SendLimits: Defines max number of emails sent by day, hour, minute or second.
    • TimePrecission: If true, shows date and time and milliseconds in log entries.
    • Host: Redis server DNS or ip.
    • Port: Redis server port.
    • LogKey: Redis will save log into this key.
    • MaxSize: Limits size of redis key. When reached, old entries are deleted.
    • Password: For access to secured Redis servers.
    • OutputAsJson: Sends log as Json.
    • Enabled: Enables/disables receive logging.
  • Quick.Logger.Provider.Memory: Saves logging into memory.

    Properties:

    • LogLevel: Log level that your provider accepts.
    • EventTypeNames: Every eventtype has a customizable text you can change to be reflected in your logs.
    • SendLimits: Defines max number of emails sent by day, hour, minute or second.
    • TimePrecission: If true, shows date and time and milliseconds in log entries.
    • MaxSize: Limits size. When reached, old entries are deleted.
    • MemLog: Object list containing all log item entries.
    • AsStrings: Returns a TStringList containing all log item entries.
    • AsString: Returns a string containing all log item entries.
    • Enabled: Enables/disables receive logging.
  • Quick.Logger.Provider.Telegram: Send log as a message to public/private Telegram channel. (You need token of a bot in this channel)

    Properties:

    • LogLevel: Log level that your provider accepts.
    • EventTypeNames: Every eventtype has a customizable text you can change to be reflected in your logs.
    • SendLimits: Defines max number of emails sent by day, hour, minute or second.
    • TimePrecission: If true, shows date and time and milliseconds in log entries.
    • ChannelName: Name of channel to send messages. If its a private channel, ChannelName will be an Id. QuickLogger can get this Id automatically if bot has sent a message to this channel first. You can get it with this request https://api.telegram.org/bot/getUpdates
    • ChannelType: Private or Public channel.
    • BotToken: Telegram bot token key.
    • Enabled: Enables/disables receive logging.
  • Quick.Logger.Provider.Slack: Send log as a message to public/private Slack channel.

    Properties:

    • LogLevel: Log level that your provider accepts.
    • EventTypeNames: Every eventtype has a customizable text you can change to be reflected in your logs.
    • SendLimits: Defines max number of emails sent by day, hour, minute or second.
    • TimePrecission: If true, shows date and time and milliseconds in log entries.
    • ChannelName: Name of channel to send messages.
    • UserName: Name included as sender.
    • WebHookURL: Webhook with permissions to send to the channel. https://api.slack.com/incoming-webhooks
    • Enabled: Enables/disables receive logging.
  • Quick.Logger.Provider.ADODB: Saves log to ADO database (MSSQL, MSAccess, etc..).

    Properties:

    • LogLevel: Log level that your provider accepts.
    • EventTypeNames: Every eventtype has a customizable text you can change to be reflected in your logs.
    • SendLimits: Defines max number of emails sent by day, hour, minute or second.
    • TimePrecission: If true, shows date and time and milliseconds in log entries.
    • DBConfig: Database config.
    • ConnectionString: Alternativelly, you can specify a connectionstring directly.
    • FieldsMapping: Customizes your log fields, mapping each log field with its corresponding database field.
    • Enabled: Enables/disables receive logging.
  • Quick.Logger.Provider.SysLog: Sends Logging to SysLog server.

    Properties:

    • LogLevel: Log level that your provider accepts.
    • EventTypeNames: Every eventtype has a customizable text you can change to be reflected in your logs.
    • SendLimits: Defines max number of emails sent by day, hour, minute or second.
    • TimePrecission: If true, shows date and time and milliseconds in log entries.
    • Host: SysLog server host.
    • Port: SysLog server port.
    • Facility: Type of program is logging to syslog.
    • Enabled: Enables/disables receive logging.
  • Quick.Logger.Provider.Logstash: Sends Logging to Logstash service.

    Properties:

    • LogLevel: Log level that your provider accepts.
    • EventTypeNames: Every eventtype has a customizable text you can change to be reflected in your logs.
    • SendLimits: Defines max number of emails sent by day, hour, minute or second.
    • TimePrecission: If true, shows date and time and milliseconds in log entries.
    • URL: Host
    • JsonOutputOptions: Json options to format output json.
    • IndexName: ElasticSearch index name.
    • DocType: Entry document type.
    • Enabled: Enables/disables receive logging.
  • Quick.Logger.Provider.ElasticSearch: Sends Logging to ElasticSearch server.

    Properties:

    • LogLevel: Log level that your provider accepts.
    • EventTypeNames: Every eventtype has a customizable text you can change to be reflected in your logs.
    • SendLimits: Defines max number of emails sent by day, hour, minute or second.
    • TimePrecission: If true, shows date and time and milliseconds in log entries.
    • URL: Host and port
    • JsonOutputOptions: Json options to format output json.
    • IndexName: ElasticSearch index name.
    • DocType: Entry document type.
    • Enabled: Enables/disables receive logging.
  • Quick.Logger.Provider.InfluxDB: Sends Logging to InfluxDB Database.

    Properties:

    • LogLevel: Log level that your provider accepts.
    • EventTypeNames: Every eventtype has a customizable text you can change to be reflected in your logs.
    • SendLimits: Defines max number of emails sent by day, hour, minute or second.
    • URL: Host and port
    • Database: Database name.
    • UserName: Database username.
    • Password: Database password.
    • CreateDatabaseIfNotExists: Creates influxdb database if not exists on server.
    • IncludedTags: Tags included to influxdb.
    • Enabled: Enables/disables receive logging.
  • Quick.Logger.Provider.GrayLog: Sends Logging to GrayLog service.

Properties:

  • LogLevel: Log level that your provider accepts.
  • EventTypeNames: Every eventtype has a customizable text you can change to be reflected in your logs.
  • SendLimits: Defines max number of emails sent by day, hour, minute or second.
  • URL: Host and port
  • GrayLogVersion: GrayLog version to send to server.
  • ShortMessageAsEventType: If enabled, shortmessage will be eventype as string and fullmessage will be the log message.
  • Enabled: Enables/disables receive logging.

Optional output:

QuickLogger allows to select with info to log. You can include HOSTNAME, OS Version, AppName, Platform or Environment(production, test, etc) 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:

  • Platform: Define your log source (API, Destokp app or your own value).
  • Environment: Define your environment (Production, Test, develop or your own value).
  • AppName: Uses default filename without extension, but can be customized.
  • IncludedInfo: Define which fields do you want to include as part of your log info.
GlobalLogConsoleProvider.IncludedInfo := [iiAppName,iiHost,iiEnvironment,iiPlatform];
  • CustomMsgOutput: If enabled, LogItem.Msg field is only included as output. It ables to send customized json to redis, rest, etc.
GlobalLogRedisProvider.CustomMsgOutput := True;
Log('{"level":"warn","text":"my text"}',etInfo);

Load/Save Config:

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]"
		}	
}

Logging Exceptions:

QuickLogger can capture your application exceptions. There are 3 exception hooks. You need to add one or more units to your uses clause:

  • Quick.Logger.ExceptionHook: Receive every raise exception. QuickLogger receives even try..except exceptions.
  • Quick.Logger.RuntimeErrorHook: Receive runtime errors.
  • Quick.Logger.UnhandledExceptionHook: Receive only unhandled exceptions (not in try..except block).
You can’t perform that action at this time.