#1 2020-04-24 12:37:21

urhen
Member
Registered: 2020-02-13
Posts: 36

Questions about using TSynLog in own code

Hello,
I'm thinking about replacing my current logging system with the TSynLog from mORMot as it has some features I'd like to have to get better information on what is going on.
It should work on Windows/Linux (Delphi+FPC) with giving the same informations if possible (like on exceptions, serialization of Objects, etc). I'm not interested in (internal) logs from mORMot as this works quite fine smile
My questions:
1. Is this code still needed for FPC or does it work in the same way as Delphi does?

procedure TMyDB.SQLExecute(const SQL: RawUTF8);
var ILog: ISynLog;  <-- still needed for FPC or fixed meanwhile?
begin
  ILog := TSynLogDB.Enter(self,'SQLExecute');
  // do some stuff
  ILog.Log(sllInfo,'SQL=%',[SQL]);
end; // when you leave the method, it will write the corresponding event to the log

2. Is there a way to change the logfile output? In my current log system I've separated it into sections (GUI, USER, DOWNLOAD, etc), is there a way to add them into the log as well? It also writes the thread ID to the line so that it can be better traced.

20110325 19325801  +    MyDBUnit.TMyDB(004E11F4).SQLExecute
20110325 19325801 info   SQL=SELECT * FROM Table;
20110325 19325801  -    MyDBUnit.TMyDB(004E11F4).SQLExecute 

3. If I have different kinds of log levels will it always write the entry/exit (+ and -) of a function to the log? E.g. for errors I'd also like to know when it happens and don't need any other infos collected
4. Can the log level be changed on runtime?
5. Is it a good idea to put the Enter/Leave logging into each function or will it slowdown my program too much?
6. Is there anything else I should aware of?

Kind Regards
urhen

Offline

#2 2020-04-24 14:59:02

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

Re: Questions about using TSynLog in own code

1. No, FPC still has a more restricted scope for interfaces: you need a local ISynLog variable.
OR you can use a

with TSynLogDB.Enter do 
begin
 ...
 end;

2. I don't understand what you call a "section".
The Thread ID is supported directly in TSynLog. Use PerThreadLog := ptIdentifiedInOnFile
The GUI LogViewer has all you need for very efficient thread filtering.

3. Did you check TSynLogFamily.Levels?

4. Did you try? Yes, it can.

5. Add Enter/Leave only when relevant - very small functions may just need a single  log line (with timing if needed).

6. Read the docs about logging again.

Offline

#3 2020-04-24 21:50:21

urhen
Member
Registered: 2020-02-13
Posts: 36

Re: Questions about using TSynLog in own code

2. I separated my program into "sections" so that it's a bit more sorted in the current logging mechanism I use.
output line looks like: <time> <threadid> <section> <log level> <text message>
3. Yes, I saw that there are a lot levels defined in TSynLogInfo but it's not fully clear to me what they exactly do. E.g. sllExceptionOS will log all exceptions which occur inside this function OR should it be used by me if I log an exception which was caught by a try..except block? Same for sllTrace which says "will log low-level step by step debugging information" but don't know what that exactly mean as output.
5. Yes, I meant for timing purposes only (to find bottlenecks e.g.) That's why I asked about 1. and if the code stills needs to be like that for FPC.

Offline

#4 2020-05-08 01:04:03

urhen
Member
Registered: 2020-02-13
Posts: 36

Re: Questions about using TSynLog in own code

ab wrote:

1. No, FPC still has a more restricted scope for interfaces: you need a local ISynLog variable.
OR you can use a

with TSynLogDB.Enter do 
begin
 ...
 end;

Can't it be fixed by using this SmartPtr implementation?
It would just need to be used internally when doing

TSynLogDB.Enter(self,'SQLExecute');

Offline

Board footer

Powered by FluxBB