On Tue, 21 Sep 2010, phoebus phoebus wrote:

Hi,

I'm using FPC 2.2.4 with Lazarus.

The unit eventlog is great for logging events. SO i use it.
 
My question is how to change the default location for the filename for Linxu ssytem which is harcoded in the code.
The documentation for TEventLog.FileName wrote:
" FileName is the name of the log file used to log messages (...). The file is then located in the "/tmp" directory on unix-like systems, or in the application directory for Dos/Windows like systems
 
Line 56 to 60 from eventlog.inc (fpc\2.2.4\source\packages\fcl-base\src\unix)
    Function TEventLog.DefaultFileName : String;
    begin
      Result:='/tmp/'+ChangeFileExt(ExtractFileName(Paramstr(0)),'.log');
    end;
I can of course change the function code like Windows to have the log in the same directory thtat the application.:
Line 18 to 22 from eventlog.inc (fpc\2.2.4\source\packages\fcl-base\src\windows)
    Function TEventLog.DefaultFileName : String;
    begin
      Result:=ChangeFileExt(Paramstr(0),'.log');
    end;

Could you indicate a nice solution to indicate log file location in using the unit eventlog without change fpc code?

You can just set the filename property, with full path:
/my/path/mylog.txt

It will be created in the path you specify, as you can see in ActivateFileLog.

Procedure TEventLog.ActivateFileLog;

begin
  If (FFileName='') then
    FFileName:=DefaultFileName;
  // This will raise an exception if the file cannot be opened for writing !
  FStream:=TFileStream.Create(FFileName,fmCreate or fmShareDenyWrite);
end;

The default is just that, the default. If you specify a filename, then that
is used. What more do you need ?

Michael.
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to