#1 2024-01-08 16:58:56

nakisen
Member
Registered: 2021-04-30
Posts: 9

Saving the archive log file as zip

Hi

I want to save the log file to be archived as a zip. But it keeps saving as "synlz".

  with TSynLog.Family do
    begin
      //AutoFlushTimeOut:=10;
      RotateFileCount:=100;
      RotateFileSizeKB:=20; //test size
      Level := LOG_VERBOSE;
      PerThreadLog := ptIdentifiedInOnFile;
      EchoToConsole := LOG_VERBOSE;
      FileExistsAction:=acAppend;
      CustomFileName:='project_test';
      OnArchive:=mormot.core.zip.EventArchiveZip;
    end;
// mormot.core.zip

function EventArchiveZip(const aOldLogFileName, aDestinationPath: TFileName): boolean;
var
  n: integer;
begin
  result := false;
  if aOldLogFileName = '' then   <<<  This function fired but, "aOldLogFileName" is empty string.
    FreeAndNilSafe(EventArchiveZipWrite)
  else
  begin
    if not FileExists(aOldLogFileName) then
      exit;
    if EventArchiveZipWrite = nil then
      EventArchiveZipWrite := TZipWrite.CreateFrom(
        copy(aDestinationPath, 1, length(aDestinationPath) - 1) + '.zip');
    n := EventArchiveZipWrite.Count;
    EventArchiveZipWrite.AddDeflated(aOldLogFileName, {removepath=}true);
    if (EventArchiveZipWrite.Count = n + 1) and
       DeleteFile(aOldLogFileName) then
      result := true;
  end;
end;

Last edited by nakisen (2024-01-08 16:59:15)

Offline

#2 2024-01-09 11:54:27

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,238
Website

Re: Saving the archive log file as zip

My guess is that your expectations are wrong about this feature.
Please read again the documentation.
My guess is that your archive files are not older than 7 days, which is the default ArchiveAfterDays value.

OnArchive is done when you close the program, from TSynLogFamily.Destroy.
If there are some log files older than ArchiveAfterDays, then OnArchive() will be called with the old mpg file name and the zipping should take place.
If there are NO log files older than ArchiveAfterDays,  then OnArchive() won't be called.
A final OnArchive() with aOldLogFileName = '' is always eventually made, to close the pending TZipWrite instance.

So I guess that what you observed is as expected.

Offline

#3 2024-01-09 18:11:25

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,238
Website

Re: Saving the archive log file as zip

Edit:

The OnArchive() features was in fact not really finalized.
I have made a lot of enhancements, and also some fixes.
https://github.com/synopse/mORMot2/commit/e7bf4132

My guess is that now it is more useful, and should work as expected.
At least, it should be less confusing now. wink

Offline

Board footer

Powered by FluxBB