Sign in Join

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

Catalog · How the catalog works

Random project

Logging4Delphi

API that facilitates the generation of logs in applications developed in 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

Logging For Delphi

The Logging4Delphi is an API that facilitates the generation of logs in applications developed in Delphi. With this library you can configure the task of logging in an easy and simple way. Moreover, it enables the use of the framework Log4D that has a lot of classes and methods for generating logs.

Drivers Adapters

The Logging4Delphi is available for the following data access drivers:

  • Logging with standard adapter;
  • Logging with Log4D adapter;

External Dependencies

The Logging4Delphi makes use of some external dependencies. Therefore these dependences are included in the project within the "dependencies" folder. If you use the library parser you should add to the Path Log4D.

Using Logging4Delphi

The Logging4Delphi requires Delphi 2010 or greater and to use this API will is very simple, you simply add the Search Path of your IDE or your project the following directories:

  • Logging4Delphi\src
  • Logging4Delphi\dependencies\Log4D

Examples

pascal
uses
  Logging4D,
  Logging4D.Impl,
  Logging4D.Driver.Standard;
pascal
procedure LoggingWithStandardAdapter;
var
  logging: ILogging;
  appender: TLoggerAppender;
  fileName: string;
begin
  inherited;
  fileName := ExtractFilePath(ParamStr(0)) + 'Log.txt';
pascal
appender := procedure(msg: string)
  var
    strList: TStringList;
  begin
    strList := TStringList.Create;
    try
      if FileExists(fileName) then
        DeleteFile(fileName);
pascal
strList.Add(msg);
pascal
strList.SaveToFile(fileName);
pascal
finally
  strList.Free;
end;
pascal
end;
pascal
logging := TStandardLogging.Create(appender);
pascal
//Using Logger
logging.Fatal(
 TLogger.New
   .Keywords(['REST'])
   .Owner('AppOne')
   .Message('Fatal REST Request Error')
   .Marker('Delphi')
 );
pascal
//Using String Message
logging.Fatal('Fatal REST Request Error');
pascal
end;
pascal
procedure LoggingWithLog4DAdapter;
var
   logging: ILogging;
begin
   logging := TLog4DLogging.Create('Log4D', fileName);
pascal
//Using Logger
 logging.Fatal(
  TLogger.New
    .Keywords(['REST'])
    .Owner('AppOne')
    .Message('Fatal REST Request Error')
    .Marker('Delphi')
  );
pascal
//Using String Message
logging.Fatal('Fatal REST Request Error');
pascal
end;

Analyze the unit tests they will assist you.