Using the Log4delphi 0.8 log component under Delphi 7

Source: Internet
Author: User

Log4delphi is an open source project designed to produce Delphi's high-quality and practical log suite for Borland, which is based on the Apache Software Foundation's log4j package.

Installation:
1. Download the 0.8 version from http://sourceforge.net/projects/log4delphi/files/and unzip to the folder. Open Folder "... \log4delphi-0.8", create a new folder "build";
2. Run Delphi 7, open the component package "LOG4DELPHI_D7_PROF.DPK", under "... \log4delphi-0.8\src\delphi", click "Compile" and "install" to compile and install;
3. Menu "Tools" → "Environment Options" → "Library" → "Library path", add "... \log4delphi-0.8\build" directory (if you need to connect the source code, then add "... \ Log4delphi-0.8\src\delphi "and" ... \log4delphi-0.8\src\delphi\util ");
Use:
1. Create a new application to save the current project.
2. The menu "Project" → "View Source", add the initialization log, etc., the code is as follows:

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
Program Project1;

Uses
Forms,
Tconfiguratorunit, {need to reference this cell}
Unit1 in ' Unit1.pas ' {Form1};

{$R *.res}

Begin
Application.initialize;
Dopropertiesconfiguration (' log4delphi.properties '); {Initialize, read properties}
Application.createform (TForm1, Form1);
Application.Run;
End.

3. Copy "... \log4delphi-0.8\example\log4delphi.properties" to the project directory;
4. Place two buttons on the form, click the event and the form's destroy event as follows:

"
"Geneva
"
"
"
"
"
"



+
-
+
-
-
/
-
  implementation 
 
Uses tloggerunit;    {must refer to this cell} 
 
{$R  *.dfm} 
 
Procedure tform1.btn1click (sender: tobject);  
begin 
   TLogger.GetInstance.Debug (' button 1 was ordered ');    {gets Tlogger instance} 
end; 
 
Procedure  tform1.btn2click (sender: tobject);  
begin 
  tlogger.getinstance.info (' Button 2 was also ordered ');   {includes: Fatal, Error, Warn, Info, Debug, trace} 
end; 
 
procedure  Tform1.formdestroy (sender: tobject);  
begin 
  TLogger.FreeInstances;    {release}  when no use is required;
end; 

5. Run the program, click button One and button two to close the program. In the project directory, you will find a "app.log" file that opens as follows:

6. Open the properties file "Log4delphi.properties" to see some of the default properties and property descriptions. For example, you can set the log file layout, the original content is as follows:

1
2
3
4
5
6
Log4delphi.appender.fileappender.layout=tsimplelayout
#log4delphi. appender.fileappender.layout=txmllayout
#log4delphi. appender.fileappender.layout=thtmllayout
#log4delphi. Appender.fileappender.layout.title=document Title
#log4delphi. appender.fileappender.layout=tpatternlayout
#log4delphi. Appender.fileappender.layout.pattern=%d{dd mmm yyyy hh:nn:ss:zzz} [%5p]%m%n

The default is to open Tsimplelayout, which is a simple layout, formatted as above. If we need to do the log output in the time format, we need to disable Tsimplelayout and then open the Tpatternlayout and the styles below it, such as:

1
2
3
4
5
6
#log4delphi. appender.fileappender.layout=tsimplelayout
#log4delphi. appender.fileappender.layout=txmllayout
#log4delphi. appender.fileappender.layout=thtmllayout
#log4delphi. Appender.fileappender.layout.title=document Title
Log4delphi.appender.fileappender.layout=tpatternlayout
Log4delphi.appender.fileappender.layout.pattern=%d{dd mmm yyyy hh:nn:ss:zzz} [%5p]%m%n

7. Perform the 5th step again, open as shown:

8. If the time format does not meet the individual requirements, you can customize your own format, you can refer to the User Guide (http://log4delphi.sourceforge.net/userguide.html).

Extended Data:
1.log4delphi Use Experience http://www.cnblogs.com/kfarvid/archive/2010/08/02/1790641.html

Using the Log4delphi 0.8 log component under Delphi 7

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.