#1 2023-12-13 09:31:56

jienyuan
Member
Registered: 2017-07-22
Posts: 4

WebSocketsUpgrade with RemoteLogging caused ESynLogException

After I added

TRestHttpClient.CreateForRemoteLogging('localhost',TSynLog,8091) in restws_chatserver program;

  with TSynlog.Family do
    ....
  WebSocketLog := TSynLog; // verbose log of all WebSockets activity
  TRestHttpClient.CreateForRemoteLogging('localhost',TSynLog,8091);
  try
    ...
  end;

to redirect logs to Logview in rest-websockets sample.

The Client.ServerTimeStampSynchronize will hang and raised the exception in Logview.

[bold]EXC   ESynLogException {Message:"Missing TSynLog.DisableRotemoteLog(true)"} [R1:root] at 59826e  [/bold]

Have any idea? Thank you.

Offline

#2 2023-12-13 15:38:15

tbo
Member
Registered: 2015-04-20
Posts: 335

Re: WebSocketsUpgrade with RemoteLogging caused ESynLogException

jienyuan wrote:

Have any idea? Thank you.

I have created a simple unit for this:

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.UITypes, System.Classes,
  mormot.core.base, mormot.core.text, mormot.core.rtti, mormot.core.log;

type
  TRemoteLogging = class(TComponent)
  strict private
    FLogClass: TSynLogClass;
  protected
    const
      DEFAULT_PORT = 8091;
  public
    destructor Destroy; override;
    procedure Start(pmLogClass: TSynLogClass; const pmcUri: RawUtf8 = '127.0.0.1/LogService');
    procedure Stop;
  end;

implementation

uses
  mormot.net.sock,
  mormot.rest.http.client;

destructor TRemoteLogging.Destroy;
begin
  Stop;
  inherited Destroy;
end;

procedure TRemoteLogging.Start(pmLogClass: TSynLogClass; const pmcUri: RawUtf8);
var
  uri: TUri;
begin
  if pmLogClass <> Nil then
  try
    FLogClass := pmLogClass;
    uri.From(pmcUri, Int32ToUtf8(DEFAULT_PORT));
    TRestHttpsClient.CreateForRemoteLogging(uri.Server, pmLogClass, Utf8ToInteger(uri.Port), uri.Root);
  except
    on E: Exception do
      pmLogClass.Add.Log(sllError, E);
  end;
end;

procedure TRemoteLogging.Stop;
begin
  if FLogClass <> Nil then
    FLogClass.Family.EchoRemoteStop;
end;

It is used like this:

procedure TfrmMain.FormCreate(Sender: TObject);
begin
  ...
  TRemoteLogging.Create(Self).Start(TSynLog);

With best regards
Thomas

Offline

#3 2023-12-14 08:30:05

jienyuan
Member
Registered: 2017-07-22
Posts: 4

Re: WebSocketsUpgrade with RemoteLogging caused ESynLogException

Hi Thomas,

   Thanks for the promptly reply.

I did the more testing and noticed my code is working fine when not used WebSocketsEnable() function.

I activated WebSocketsEnable() and noticed there will have logs in below:

 EXC   ENetSock {LastError:"nrFatalError",Message:"THttpClientSocket.SockSendFlush(localhost) len=539 [Fatal Error - #6]"} [TRemoteLog LogService] at 637c26
 EXC   ESynLogException {Message:"Missing TSynLog.DisableRotemoteLog(true)"} [R1:root] at 59826e
 trace mormot.net.ws.async.TWebSocketAsyncProcess(025bd5c0) ProcessStop: callbacks
 debug mormot.net.ws.async.TWebSocketAsyncProcess(025bd5c0) ProcessStop {"TWebSocketProtocolBinary(025a7530)":{Name:"synopsebin",URI:"root",RemoteIP:"172.17.112.1",UpgradeUri:"root",Encrypted:true,FramesInCount:1,FramesInBytes:33,Options:["pboSynLzCompress"],FramesInBytesSocket:66,FramesInCompression:-100,FramesOutCompression:100}}
 trace mormot.net.ws.async.TWebSocketAsyncProcess(025bd5c0) SendFrame 172.17.112.1 * focConnectionClose len=0
 warn  mormot.net.ws.async.TWebSocketAsyncProcess(025bd5c0) Destroy: no focConnectionClose SendFrame

 

However, this is too far for me.

Best Regards,
JienYuan

Offline

Board footer

Powered by FluxBB