#1 2012-12-07 16:16:43

corchi72
Member
Registered: 2010-12-10
Posts: 232

why the log is empty?

sorry but I do not understand why does not work the log, I mean the file is created but nothing is written. I do not understand why.

 ....create a server 
  self.CreateMissingTables(0);
  Server := TSQLHttpServer.Create(ServerPort,[self]);//,ServerName);
  self.OnUpdateEvent := OnDatabaseUpdateEvent;

   with TSQLLog.Family do begin
    Level := LOG_VERBOSE;
    AutoFlushTimeOut := 2;
    DestinationPath := GetTempDir;
    OnArchive := EventArchiveSynLZ;
    ArchiveAfterDays := 1; // archive after one day
  end;

   TSQLLog.Add.Log(sllInfo,'test corchi');

Offline

#2 2012-12-07 16:49:50

corchi72
Member
Registered: 2010-12-10
Posts: 232

Re: why the log is empty?

I noticed that the log is sometimes written only after I closed the console application. Why?

Offline

#3 2012-12-07 17:12:28

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

Re: why the log is empty?

There is a time out flushing in a background thread.

Offline

#4 2012-12-10 10:32:32

corchi72
Member
Registered: 2010-12-10
Posts: 232

Re: why the log is empty?

sorry I read your example of the log but I was not yet clear to me, perhaps because it does not work! please you can write three lines of code that will allow me to create a log file. thanks

Offline

#5 2012-12-10 13:29:45

corchi72
Member
Registered: 2010-12-10
Posts: 232

Re: why the log is empty?

well I found the problem, I am running an application with the directive {$ APPTYPE CONSOLE}
and with the command readln go out the application.
I saw that as long as the program is started, the log does not write anything to the file which will be written only after readln

Offline

#6 2012-12-12 14:24:03

corchi72
Member
Registered: 2010-12-10
Posts: 232

Re: why the log is empty?

now I understand, I have to use TSQLlog.Family.SynLog.Flush (true) if I want the log to be written to the file before reaching the 4 kb, right?

Offline

#7 2012-12-12 15:51:56

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

Re: why the log is empty?

Or you can set the AutoFlushTimeOut property to a auto-flush time period (in seconds).

Flushing the content at every row is just very slow (due to Windows API).

If there is an exception, flush is always done (for safety).

Offline

#8 2012-12-12 16:06:49

corchi72
Member
Registered: 2010-12-10
Posts: 232

Re: why the log is empty?

ok I will use flush sparingly, however AutoFlushTimeOut = 2 + with Appconsole readln; does not work, or rather writes only when they exceed the 4 kb and my Appconsole when part does not exceed 4 kb immediately because I septum in the following way

constructor TFileServer.Create(const ServerName,ServerPort: AnsiString;const aFilename: AnsiString);
var
  inherited Create(CreateFileLicenseModel(true),aFilename,true);
  self.CreateMissingTables(0);
  Server := TSQLHttpServer.Create(ServerPort,[self]);

  with QvLog.Family do begin
    Level := [sllError,sllInfo,sllDebug,sllServiceCall]; //LOG_VERBOSE;//

    AutoFlushTimeOut := 2;
    DestinationPath := GetTempDir;
    OnArchive := EventArchiveSynLZ;
    //OnArchive := EventArchiveZip;
    ArchiveAfterDays := 1; // archive after one day
//    IncludeComputerNameInFileName:=true;
  end;

  QvLog.Add.Log(sllInfo,format('Database Name:  %s',[ExpandFileName(aFilename)]));
  QvLog.Add.Log(sllInfo,format('Server Port:  %d',[strtoint(ServerPort)]));
  QvLog.Add.Log(sllInfo,format('Server Name:  %s',[ServerName]));



  {$ifNdef SERVICE}
  writeln('Server is Started');
  {$ENDIF}
  QvLog.Add.Log(sllInfo, 'Server is Started');



  except
    on E: Exception do
    begin
		QvLog.Add.Log(sllError,'Error launching the server' +#10+E.Message);
//     handle initialization error here
    end;
  end;

  QvLog.Family.SynLog.Flush(true);
end;

and if I read the file.log want to find written:

20121212 16310611 info  Server Port:  8001
20121212 16310611 info  Server Name:  localhost
20121212 16310611 info  Server is Started

and not wait until the file reaches the size of 4kb, if I wait more than 2 seconds (as set  above -> AutoFlushTimeOut := 2;) does not write anything

Offline

#9 2012-12-12 20:36:47

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

Re: why the log is empty?

readln just does suspend the whole process, I suspect.

Offline

Board footer

Powered by FluxBB