You are not logged in.
Hi,
Is it possible to redirect server logging to a memo control on server main form ?
Offline
Hi,
I have VCL form server application (not console)
When I set TSQLLog.EchoCustom my own log writer then application is freeze.
function TfrmRestServer.Echo(Sender:TTextWriter; Level:TSynLogInfo; const
Text:RawUTF8): boolean;
begin
Memo1.Lines.Add(Text); <- without this line, not freeze
Result := true;
end;
How write log info to main form memo component?
Thanks, Csaba
Offline
TSQLLog.EchoCustom can be called from any number of threads, that memo1 line needs to be synchronized with the main thread.
Offline
Yes, think this is the problem, but I dont find solution.
TThread.Synchronize(nil,
procedure
begin
Memo1.Lines.Add(Text);
end
);
Not working.
Offline
It works just fine, it's your code somewhere that is the issue, something you are not showing. Below is quick threaded example (XE7 required or higher).
unit Unit1;
interface
uses
Winapi.Windows,
Winapi.Messages,
System.SysUtils,
System.Variants,
System.Classes,
System.Threading,
Vcl.Graphics,
Vcl.Controls,
Vcl.Forms,
Vcl.Dialogs,
Vcl.StdCtrls,
SynLog,
SynCommons;
type
TForm1 = class(TForm)
Memo1: TMemo;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
function Echo(Sender: TTextWriter; Level: TSynLogInfo; const Text: RawUTF8): boolean;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{ TForm1 }
function TForm1.Echo(Sender: TTextWriter; Level: TSynLogInfo; const Text: RawUTF8): boolean;
begin
TThread.Synchronize(nil,
procedure
begin
Memo1.Lines.Add(Text);
end);
Result := True;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
I: Integer;
aTask: ITask;
begin
with TSynLog.Family do
begin
Level := LOG_VERBOSE;
NoFile := True;
EchoCustom := Echo;
end;
for I := 0 to 1000 do
begin
aTask := TTask.Create(
procedure()
begin
TSynLog.Add.Log(TSynLogInfo.sllInfo, 'TEST');
end);
aTask.Start;
end;
end;
end.
Last edited by pvn0 (2019-04-08 07:29:13)
Offline
This part is ok, but i log all event, like consol app.
TSQLLog.Family.EchoToConsole := LOG_VERBOSE;
HTTPServer := TSQLHttpServer.Create(HTTP_PORT,[ORMServer]);
I want in form app: start server and log into all to the memo.
Minimal code:
TfrmRestServer = class(TForm)
Memo1: TMemo;
private
{ Private declarations }
FRestServer:TSQLRestServerFullMemory;
FhttpServer:TSQLHttpServer;
public
{ Public declarations }
function Echo(Sender:TTextWriter; Level:TSynLogInfo; const Text:RawUTF8):boolean;
end;
function TfrmRestServer.Echo(Sender:TTextWriter; Level:TSynLogInfo; const Text:RawUTF8): boolean;
begin
TThread.Synchronize(nil,
procedure
begin
Memo1.Lines.Add(Text);
end
);
Memo1.Lines.Add(Text);
Result := true;
end;
...
TSQLLog.Family.Level := LOG_VERBOSE;
TSQLLog.Family.NoFile := True;
TSQLLog.Family.EchoCustom := frmRestServer.Echo;
FRestServer := TSQLRestServerTest.Create(TSQLModel.Create([]));
FhttpServer := TSQLHttpServer.Create('888', [FRestServer]);
But not work, Write two line, after application is freeze.
Last edited by HollosCs (2019-04-08 08:50:24)
Offline
Please do not write so much code as part of the forum posts.
Please follow the rules - https://synopse.info/forum/misc.php?action=rules
Your code is wrong: it calls Memo1.Lines.Add(Text) twice - the 2nd call is executed in the current log thread, which is not correct.
Online
Sorry ab!
2nd line not in code, copy code accident, but not working without it also.
Which correct way to show log information in gui application?
Read periodically log file? The console echo is perfect, how can i this in forms?
Thanks, Csaba
Offline
Many thanks for everybody!
I got a solution, use TTask instead of CriticalSection or Syncronize.
Inside of EchoCustom function:
aTask := TTask.Create(procedure begin Memo1.Lines.Add(Text); end);
aTask.Start;
Result := true;
Offline
@HollosCs, I hope you don't run that code in production because it's an accident waiting to happen. If that solves your problem then you have bigger issues at hand.
My guess is you're running http and rest servers in main UI thread. You should not do that. You should create a worker thread for your server and then use a communication layer to communicate in between.
Offline
@pvn0, Of course not. Demo project for 'real time' debug for server communication to and from variable clients.
Offline