#1 2014-10-07 09:44:07

win2014
Member
Registered: 2014-06-10
Posts: 31

A newbie question about 'How to use TSynLog'

For save time, Just show my codes:

type
  TMyLog = class(TSynLog)

  end;

begin
    with TMyLog.Family do begin
      Level := LOG_VERBOSE;
      DestinationPath := ExtractFilePath(ParamStr(0)) + 'logs';
    end;

    TMyLog.Add.Log(sllInfo, 'do some stuff');
end.

I have read the sample one by one, and see that per-class knowledge, but the codes above can't work: the log file created in dir of exe, not the logs dir, the string "do some stuff" not in log file, what happends? My SynCommons is the latest version, I can ensure that.

Offline

#2 2014-10-07 16:39:31

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

Re: A newbie question about 'How to use TSynLog'

I suppose you had to include the trailing backslash to the 'logs\' value.
I've made a property setter to ensure it will be added if not specified.
See http://synopse.info/fossil/info/12b03d6a78

Thanks for the feedback.

Offline

#3 2014-10-07 17:10:26

win2014
Member
Registered: 2014-06-10
Posts: 31

Re: A newbie question about 'How to use TSynLog'

I added '/' to the 'logs', then log file go into it, but still no my log info, and I open log file, the last line is

TMyLog 1.18.311 2014-10-08T01:05:15

Offline

#4 2014-10-07 17:26:23

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

Re: A newbie question about 'How to use TSynLog'

Did you try with TSynLog directly?

Offline

#5 2014-10-07 17:32:57

win2014
Member
Registered: 2014-06-10
Posts: 31

Re: A newbie question about 'How to use TSynLog'

I have try, like the same.

Offline

#6 2014-10-08 07:48:03

cheemeng
Member
From: Malaysia
Registered: 2011-08-09
Posts: 61

Re: A newbie question about 'How to use TSynLog'

FYI, it works for me when I tried it (I have not committed the latest patch so I still manually added the trailing slash).

  with TMyLog.Family do
  begin
    Level := [sllInfo, sllError, sllServer];
    DestinationPath := ExtractFilePath(Application.ExeName) + 'logs\';
  end;

  TMyLog.Add.Log(sllInfo, 'Testing');

Question for @win2014: Does the logs folder exist?

Offline

#7 2014-10-12 03:45:10

win2014
Member
Registered: 2014-06-10
Posts: 31

Re: A newbie question about 'How to use TSynLog'

cheemeng wrote:

FYI, it works for me when I tried it (I have not committed the latest patch so I still manually added the trailing slash).

  with TMyLog.Family do
  begin
    Level := [sllInfo, sllError, sllServer];
    DestinationPath := ExtractFilePath(Application.ExeName) + 'logs\';
  end;

  TMyLog.Add.Log(sllInfo, 'Testing');

Question for @win2014: Does the logs folder exist?

Of course, I saw it. My mean is log info is not correct.

Offline

#8 2014-10-12 08:47:00

win2014
Member
Registered: 2014-06-10
Posts: 31

Re: A newbie question about 'How to use TSynLog'

I just know that TSynLog can't work reason in my testing project.
My testing project is a console project, and I add 'Readln' procedure at the end, yes, when I add it, my logs lose, when I remove it, my logs are correct!
@ab, is this a bug? Could you check it?

Last edited by win2014 (2014-10-13 03:09:32)

Offline

#9 2014-10-13 08:43:54

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

Re: A newbie question about 'How to use TSynLog'

I just right your .dpr, and here is what is written when you execute the program:

..... header ...

20141013 10403644 info  do some stuff 

So sounds right to me, right?

But you may be reading the file in debug mode.
In this case, the log content may still be in memory, not already flushed to the disk.
By default, and for a huge performance boost, data is written in a memory buffer, then written to the disk using a background thread.
If you add a "readln" after the "Add.Log" you would see all data appear in the file after a small delay.

See TSynLogFamily.BufferSize and TSynLog.Flush method or set TSynLogFamily.AutoFlushTimeOut and the corresponding documentation.

Offline

#10 2014-10-13 13:58:38

cheemeng
Member
From: Malaysia
Registered: 2011-08-09
Posts: 61

Re: A newbie question about 'How to use TSynLog'

Also, note that AutoFlushTimeOut does not work when you are in Debug mode (DebugHook = 1).

Offline

#11 2014-10-14 01:45:17

win2014
Member
Registered: 2014-06-10
Posts: 31

Re: A newbie question about 'How to use TSynLog'

ab wrote:

I just right your .dpr, and here is what is written when you execute the program:

..... header ...

20141013 10403644 info  do some stuff 

So sounds right to me, right?

But you may be reading the file in debug mode.
In this case, the log content may still be in memory, not already flushed to the disk.
By default, and for a huge performance boost, data is written in a memory buffer, then written to the disk using a background thread.
If you add a "readln" after the "Add.Log" you would see all data appear in the file after a small delay.

See TSynLogFamily.BufferSize and TSynLog.Flush method or set TSynLogFamily.AutoFlushTimeOut and the corresponding documentation.

Ok, I add AutoFlushTimeOut := 1; then the log string appear.
Thanks.

Offline

Board footer

Powered by FluxBB