THotLog

[ Home ]



Log file properties

hLog writes everything in a file which is owned and managed by the writer thread. For that reason, the log file definition object has been made a property of the wrtiter thread, instead of declaring more anf more methodes into THotLog itself.

You will then have to acces it through the writer thread instance: hLog.hlWriter.hlFileDef.someProperty.

Please note also that it is obvious that those settings can be changed before you call hLog.StartLogging or a hLog.Add procedure for the first time.
It's not possible to change some log file and writer thread properties later.


.ddname: String;

The part of the filename after the path and before the extention.
Default: Your program's name.


.path: String;

The path of the logFile.
Default: Your programm's path.


.ext: String;

The extention.
If an extention is provided, generations are no longer managed.
Default: .log


.fileName: TFileName;

The long file name: path + name + extention


.append: Boolean;

If true and a previous file exists, new data will be appended, gdgMax is set to 0 and generations are no longer managed.
Default: False


.GdgMax: Word;

The number of generations files to keep. Can range from 0 to 999.
If set to 0 (and .append is False), a new log file is created each time your application starts.
If set to one, a new file is created too, with the extention ".001".
If more than one, HotLog will create a new file each time your application starts, until the max number of generations is reached.
When reached, the oldest one will be deleted, all the others will be renamed, and the new one. The oldest one has the extention ".001", the most recent one is the one with the highest extention number.
Default: False


.OpMode: Word;

Read only property.
The open mode for the log file. Depends of preceding topics. Used internally.


.LogFileMaxSize: Integer;

Maximum size of the log file, used for continuous operation.
HotLog instances can monitor the size of the log file and close it and open a new one when a certain limit is reached (feature added by Rob Becker).
You can use whatever you want. Robert defined constants for this, which name are explicit enough:
  OneKilobyte = 1024;
  OneMegabyte = OneKilobyte * 1024;
  TenMegabyte = OneMegabyte * 10;
Default: 0 (unlimited)
Remenber that these values are approximative limits because a HotLog message will not be interrupted.


.UseSafeFilenames: Boolean;

Generate a unique name for each log file.
"Safe" filenames are names that we can beleive to be "unique". The filename is build with the current date, time and an internal index: yyyy-mm-dd hh.mm.ss index
Use .ddname to define a common prefix for all safe names. In this case the the filename is ddname-yyyymmdd-hhmmss-index
Default: False


.SafeGdgMax: Word;

You should use this if you set a maximum to the number of safe log files generations.
Once the maximum will be reached, hLog will try to delete the older ones. To be used instead of gdgMax if you use safe file names.
Default: 0

 

Examples of use (with an exe being for example "C:\tools\MyProg.exe"):

=> Changing nothing:

The log file full name will be "C:\tools\MyProg.log"
Only one file. Will be overwritten at every startup.

 

=> Setting the ddName:

The log file full name will be "C:\tools\AnotherLogName.log"
Only one file. Will be overwritten at every startup.

 

=> Defining a generation based file, limited to five generations:

Will create and maintain up to five log generations:
"C:\tools\MyProg.001" to "C:\tools\MyProg.005"
HotLog will open a new generation log file at every startup.

 

=> Defining a size limit for the log file, and a maximum of five generations:

Will create and maintain up to five log generations:
"C:\tools\MyProg.001" to "C:\tools\MyProg.005"
HotLog will open a new generation log file at every startup and whenever a file reached 1k.


unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants,
  Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls, ComCtrls,
  HotLog;

type
  TForm1 = class(TForm)
    Timer1: TTimer;
    Memo1: TMemo;
    procedure Timer1Timer (Sender: TObject);
    procedure FormCreate  (Sender: TObject):
    procedure FormDestroy (Sender: TObject);
    private
      { Private declarations }
    public
      { Public declarations }
  end;

implementation
{$R *.dfm}

const SeventyCharsOfJunk = '1234567890123456789012345678901234567890123456789012345678901234567890';

var Counter: integer;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  hLog.AddStr('Counter = ' + IntToStr(Counter) + ' ' + DateTimeToStr(Now) + SeventyCharsOfJunk);
  inc(counter);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Counter := 1;
  hLog.hlWriter.hlFileDef.path := ExtractFilePath(Application.ExeName);
  hLog.hlWriter.hlFileDef.UseFileSizeLimit := true;
  hLog.hlWriter.hlFileDef.LogFileMaxSize := OneKilobyte;
  hLog.hlWriter.hlFileDef.UseSafeFilenames := true;
  if hLog.hlWriter.hlFileDef.UseSafeFilenames then
  begin
    hLog.hlWriter.hlFileDef.BuildSafeFilename;
    hLog.hlWriter.hlFileDef.SafeGdgMax := 5;
  end else
  begin
    hLog.hlWriter.hlFileDef.ddname := 'LogTest';
    hLog.hlWriter.hlFileDef.GdgMax := 5;
  end;
  hlog.SetLogFileTimerInterval(OneMinute);
  hLog.DisplayFeedBackInto(Memo1);
  hLog.ScrollMemo(true);
  hLog.SetMemoLimit(5000);
  hlog.StartLogging;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  hlog.StopVisualFeedBack;
end;