#1 2019-04-02 11:55:12

mpv
Member
From: Ukraine
Registered: 2012-03-24
Posts: 1,571
Website

SynLog: non-english exception logging for FPC

I found a problem on localized Windors - in case Exception text contains non-english characters it's logged with wrong codepage (broken text from user POW). My actual excaption comes from OleDB ("Class not registeder" in russian), but the simple program to reproduce is

program Project1;
uses
  sysutils, SynLog;
begin
  TSynLog.Family.Level := LOG_VERBOSE;
  try
    raise Exception.create('ошибка');
  finally
  end;
end.

I expect string "ошибка" in UTF8 encoding inside logs but instead got abracadabra.

Not shure I'm fix this correctly in #182 pull request - @ab - please review a pull request

Last edited by mpv (2019-04-02 11:56:32)

Offline

#2 2019-04-06 11:43:58

mpv
Member
From: Ukraine
Registered: 2012-03-24
Posts: 1,571
Website

Re: SynLog: non-english exception logging for FPC

@ab, please, take a look at this. Any comment is helpfull

Offline

#3 2019-04-08 06:42:44

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

Re: SynLog: non-english exception logging for FPC

See my comment in the commit.

Offline

#4 2019-04-09 20:49:23

mpv
Member
From: Ukraine
Registered: 2012-03-24
Posts: 1,571
Website

Re: SynLog: non-english exception logging for FPC

On windows with cyrilic localization

 TSynAnsiConvert.Engine(0) = TSynAnsiFixedWitdh(1251) = TSynAnsiConvert.Engine(GetACP); // GetACP == 1251 

But I made another attempt to fix. It based on fact what for fpc > 3 string = utf8 string as described in FPC WiKi.
May be 0a08e1c commit is more correct?

Last edited by mpv (2019-04-09 20:50:54)

Offline

#5 2019-04-15 15:10:38

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

Re: SynLog: non-english exception logging for FPC

What could be wrong with:

procedure InitSynCommonsConversionTables;
....
  {$ifdef FPC}
  {$ifdef ISFPC27}
  {$ifndef MSWINDOWS}
  GetACP := CP_UTF8; // hardwire string=AnsiString to UTF-8 encoding on any POSIX system
  {$endif MSWINDOWS}
  SetMultiByteConversionCodePage(CP_UTF8);
  SetMultiByteRTLFileSystemCodePage(CP_UTF8);
  {$endif ISFPC27}
  {$endif FPC}

Offline

#6 2019-04-22 07:32:35

mpv
Member
From: Ukraine
Registered: 2012-03-24
Posts: 1,571
Website

Re: SynLog: non-english exception logging for FPC

Everything is OK for in InitSynCommonsConversionTables under Unix even if

  
{$ifndef MSWINDOWS}
  GetACP := GetSystemCodePage;
{$endif MSWINDOWS}

My problem is under Windows, where GetACP is a function from kernel32 and in case of cyrilic windows localization it return  1251 sad

BTW I made another patch for SynLog to write environment variables values to log using UTF8 encoding pull #189
Current implementation log unicode variables values in OEM encoding (as returned by GetEnvironmentStringsA) and it's become unreadable on other computers, because we even don't know what code page is set as console code page on the log source machine. For example on cyrilic windows it logged as CP866 encoded

Last edited by mpv (2019-04-22 07:38:42)

Offline

#7 2019-04-25 09:32:06

mpv
Member
From: Ukraine
Registered: 2012-03-24
Posts: 1,571
Website

Re: SynLog: non-english exception logging for FPC

@ab - I add additional description for Unicode Environment variable patch - please, review a pull #189

Offline

Board footer

Powered by FluxBB