#1 2015-02-07 13:40:24

ASiwon
Member
From: Poland
Registered: 2015-01-30
Posts: 82

Extension of TSynLog and ISynLog question/proposal.

Is it possible to add to the interface ISynLog and TSynLog class method:

    procedure Log(Level: TSynLogInfo; const Text: String; Instance: TObject=nil; TextTruncateAtLength: integer=maxInt); overload;

which will convert value from Text parameter to RawUTF8 format and will call regular Log method? Now if I want to logging value from variable of type string then I must to use function StringToUTF8 in every call. A just want to avoid warning:

W1057 Implicit string cast from 'string' to 'RawUTF8'

Usually I'm writing class helper to do conversion in cases like this but it is impossible to use class helper with interfaces.


best regards
Adam Siwon

Offline

#2 2015-02-07 15:00:02

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

Re: Extension of TSynLog and ISynLog question/proposal.

The easy workaround was to use

Log(aLevel,'%',[aStringVariable]);

But I've added the overloaded method.
See http://synopse.info/fossil/info/0329a4ea67

Offline

#3 2015-02-13 13:29:39

ASiwon
Member
From: Poland
Registered: 2015-01-30
Posts: 82

Re: Extension of TSynLog and ISynLog question/proposal.

thank you very much for change - it works as expected. I have yet one logging related problem. If in the log message are used polish national chars then those chars are completely damaged in log file. For example if I'm trying to log message like this:

  log.Log(sllInfo, '% ąćęłńóśźż ĄĆĘŁŃÓŚŹŻ', ['Test:']);

Of course it is only a stupid example to show the problem. In the log file this message will be visible as:

20150213 14141308 info          Test: ڦ괱? Ɔʣғ̏

Is it possible to correct this problem or just national chars shouldn't be used in logging messages?


best regards
Adam Siwon

Offline

#4 2015-02-13 14:49:21

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

Re: Extension of TSynLog and ISynLog question/proposal.

The log write the content as UTF-8.
So I guess the issue may come from the fact that your constant string is compiled as UTF-8, not as some text with the polish codepage.
Which version of Delphi are you using?
Are you sure your source code file is defined as UTF-8 in the IDE?

Offline

#5 2015-02-13 21:23:13

ASiwon
Member
From: Poland
Registered: 2015-01-30
Posts: 82

Re: Extension of TSynLog and ISynLog question/proposal.

Hello,

it is not a problem of mORMot but my mistake. I wrote log message when a pas file was formatted as Ansi. After that I have changed file format to the UTF8 format but national chars was still encoded in Ansi format. If format of file set to UTF8 before writing message for logging then everything works correctly.


best regards
Adam Siwon

Offline

#6 2015-02-13 22:50:09

ASiwon
Member
From: Poland
Registered: 2015-01-30
Posts: 82

Re: Extension of TSynLog and ISynLog question/proposal.

Hello,

the problem is not completely resolved yet. I still have two separated messages for which messages are written incorrectly. But I can't explain why or reproduce this problem in small example. The files are formatted as UTF8 and I'm using DelphiXE4. For this code:

    log.Log(sllDebug, 'Dane ważenia: %', [RecordSaveJSON(AWazenieDane, TypeInfo(TBkWazenieDane))]));

result in the log file looks like:

20150213 23210351 debug         Dane waࠥnia: {"WagaId":281,"WagonGranicaObciazenia":56000,"WagonNumer":"315153289715","WagonNumerRodzaj":"wnrWagonUIC","WagonPobytId":0,"WagonTaraZBelki":24000,"WagowyDane":"Jaś Wagowy","WagowyNazwisko":"","WagowyImie":"","WazenieCzas":"2015-02-13T23:21:03","WazenieId":256,"WazenieLadunekNazwa":"","WazenieLadunekNumer":"","WazenieMasaBrutto":24200,"WazenieMasaNetto":0,"WazenieRodzaj":2,"WazenieRodzajPotwierdz":false,"WazeniePosrednie":false,"WazenieSklad":"10","WazenieTechnologiczne":false}

But for this code:

    log.Log(sllDebug, '% %', ['Dane ważenia:', RecordSaveJSON(AWazenieDane, TypeInfo(TBkWazenieDane))]);

result in the log file is correct and looks like:

20150213 23395624 debug         Dane ważenia: {"WagaId":281,"WagonGranicaObciazenia":56000,"WagonNumer":"315153289715","WagonNumerRodzaj":"wnrWagonUIC","WagonPobytId":0,"WagonTaraZBelki":24000,"WagowyDane":"Jaś Wagowy","WagowyNazwisko":"","WagowyImie":"","WazenieCzas":"2015-02-13T23:39:56","WazenieId":256,"WazenieLadunekNazwa":"","WazenieLadunekNumer":"","WazenieMasaBrutto":24200,"WazenieMasaNetto":0,"WazenieRodzaj":2,"WazenieRodzajPotwierdz":false,"WazeniePosrednie":false,"WazenieSklad":"10","WazenieTechnologiczne":false}

Because this problem has incidental nature this workaround is completely enough for me.


best regards
Adam Siwon

Offline

#7 2015-02-14 10:10:15

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

Re: Extension of TSynLog and ISynLog question/proposal.

I suppose the issue comes from the fact that the parameter is

  PWinAnsiChar = type PAnsiChar;

so the compiler does not know the code page used for it, so use the default system code page, as with plain AnsiChar.

On our side, we rely on plain English for all internal logging work and design (since English is the new "sabir" language).
But this PWinAnsiChar / PUTF8Char use with constant strings is indeed very confusing, and should be fixed.
BTW it broke the Delphi 5 compiler.

I've made a huge code refactoring to change:
- all PWinAnsiChar parameters into RawUTF8 constants for logging;
- all PUTF8Char parameters into RawUTF8 constants for FormatUTF8(), as used e.g. for all ORM "where" clause.
See http://synopse.info/fossil/info/a0eb5fb484

Hope it helps.
Thanks for your feedback!

Offline

#8 2015-02-14 21:31:47

ASiwon
Member
From: Poland
Registered: 2015-01-30
Posts: 82

Re: Extension of TSynLog and ISynLog question/proposal.

Hello,

I have tried to compile mORMot after changes. Now it is impossible to compile mORMot units when define WITHLOG is declared. It is because for procedure DebuggerNotify order of parameters was changed.


best regards
Adam Siwon

Offline

#9 2015-02-15 05:03:41

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

Re: Extension of TSynLog and ISynLog question/proposal.

Are you sure you download all units?

By default, WITHLOG is defined in Synopse.inc and we have no problem on our side when compiling the new version.
We tried to change all source code locations.

Offline

#10 2015-02-15 10:15:36

ASiwon
Member
From: Poland
Registered: 2015-01-30
Posts: 82

Re: Extension of TSynLog and ISynLog question/proposal.

I have no idea why error not exists on your side. The problem occurs only while compiling unit mORMotSQLite3.pas. Here is part of this unit. As you can see parameters for DebuggerNotify procedure are set in wrong order.

function SQLVarToSQlite3Context(const Res: TSQLVar; Context: TSQLite3FunctionContext): boolean;
var tmp: array[0..31] of AnsiChar;
begin
  case Res.VType of
    ftNull:
      sqlite3.result_null(Context);
    ftInt64:
      sqlite3.result_int64(Context,Res.VInt64);
    ftDouble:
      sqlite3.result_double(Context,Res.VDouble);
    ftCurrency:
      sqlite3.result_double(Context,Res.VCurrency);
    ftDate: begin
      DateTimeToIso8601ExpandedPChar(Res.VDateTime,tmp);
      sqlite3.result_text(Context,tmp,-1,SQLITE_TRANSIENT_VIRTUALTABLE);
    end;
    // WARNING! use pointer(integer(-1)) instead of SQLITE_TRANSIENT=pointer(-1)
    // due to a bug in Sqlite3 current implementation of virtual tables in Win64
    ftUTF8:
      if Res.VText=nil then
       sqlite3.result_text(Context,@NULCHAR,0,SQLITE_STATIC) else
       sqlite3.result_text(Context,Res.VText,-1,SQLITE_TRANSIENT_VIRTUALTABLE);
    ftBlob:
      sqlite3.result_blob(Context,Res.VBlob,Res.VBlobLen,SQLITE_TRANSIENT_VIRTUALTABLE);
    else begin
      {$ifdef WITHLOG}
      SynSQLite3Log.DebuggerNotify(sllWarning,[ord(Res.VType)],'SQLVarToSQlite3Context(%)');
      {$endif}
      result := false; // not handled type
      exit;
    end;
  end;
  result := true;
end;

This code was just updated from github repository.


best regards
Adam Siwon

Offline

#11 2015-02-15 11:25:41

AOG
Member
Registered: 2014-02-24
Posts: 490

Re: Extension of TSynLog and ISynLog question/proposal.

Can confirm !

Offline

#12 2015-02-15 11:49:47

AOG
Member
Registered: 2014-02-24
Posts: 490

Re: Extension of TSynLog and ISynLog question/proposal.

Additional in SynLog.pas:
On ARM (Raspberry Pi [2]) this does not compile anymore (due to incompatible asm [three times]):

{$ifdef CPU64}
{$ifdef MSWINDOWS}
if RtlCaptureStackBackTrace(1,1,@Caller,nil)=0 then
   Caller := 0 else
   dec(Caller,5); // ignore caller op codes
{$else}
   Caller := 0; // no stack trace yet under Linux64
{$endif}
{$else}
asm
  mov eax,[ebp+16] // +4->_IntfClear +16->initial caller
  mov aStackFrame,eax
end;
caller := aStackFrame-5;
{$endif} 

Offline

#13 2015-02-15 13:16:48

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

Re: Extension of TSynLog and ISynLog question/proposal.

@ASiwom
Don't know why, but some files were not committed yesterday evening.
Saturday night fever?
hmm
My mistake.

Everything should be included in http://synopse.info/fossil/info/9b60596cae
(also some other enhancements)


@AOG
See http://synopse.info/fossil/info/93c780fe9b

Offline

#14 2015-02-15 19:50:14

ASiwon
Member
From: Poland
Registered: 2015-01-30
Posts: 82

Re: Extension of TSynLog and ISynLog question/proposal.

No problem. Thank you very much for great support. Now everything is working correctly.


best regards
Adam Siwon

Offline

Board footer

Powered by FluxBB