We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
can you please add FMX logger support, like below or change by compiler directive
unit LoggerPro.FMXMemoAppender; { <@abstract(The unit to include if you want to use the @link(TFMXMemoLogAppender)) @author(Daniele Teti) }
interface
uses LoggerPro, System.Classes, FMX.StdCtrls;
type { @abstract(Appends formatted @link(TLogItem) to a TMemo in a VCL application) } TFMXMemoLogAppender = class(TLoggerProAppenderBase) private FMemo: TMemo; FMaxLogLines: Word; FClearOnStartup: Boolean; public constructor Create(aMemo: TMemo; aMaxLogLines: Word = 100; aClearOnStartup: Boolean = False); reintroduce; procedure Setup; override; procedure TearDown; override; procedure WriteLog(const aLogItem: TLogItem); override; end;
implementation
uses System.SysUtils, Winapi.Windows, Winapi.Messages;
const DEFAULT_LOG_FORMAT = '%0:s [TID %1:-8d][%2:-10s] %3:s [%4:s]';
{ TVCLMemoLogAppender }
constructor TFMXMemoLogAppender.Create(aMemo: TMemo; aMaxLogLines: Word; aClearOnStartup: Boolean); begin inherited Create; FMemo := aMemo; FMaxLogLines := aMaxLogLines; FClearOnStartup := aClearOnStartup; end;
procedure TFMXMemoLogAppender.Setup; begin if FClearOnStartup then begin TThread.Synchronize(nil, procedure begin FMemo.Clear; end); end; end;
procedure TFMXMemoLogAppender.TearDown; begin // do nothing end;
procedure TFMXMemoLogAppender.WriteLog(const aLogItem: TLogItem); var lText: string; begin lText := Format(DEFAULT_LOG_FORMAT, [datetimetostr(aLogItem.TimeStamp), aLogItem.ThreadID, aLogItem.LogTypeAsString, aLogItem.LogMessage, aLogItem.LogTag]); TThread.Queue(nil, procedure begin FMemo.Lines.BeginUpdate; try if FMemo.Lines.Count = FMaxLogLines then FMemo.Lines.Delete(0); FMemo.Lines.Add(lText) finally FMemo.Lines.EndUpdate; end; SendMessage(FMemo.Handle, EM_SCROLLCARET, 0, 0); end); end;
end.
The text was updated successfully, but these errors were encountered:
Why don't use the "Unit Scope" for this?
Sorry, something went wrong.
where can I get this unit ? How to use ?
No branches or pull requests
can you please add FMX logger support, like below or change by compiler directive
unit LoggerPro.FMXMemoAppender;
{ <@abstract(The unit to include if you want to use the @link(TFMXMemoLogAppender))
@author(Daniele Teti) }
interface
uses
LoggerPro,
System.Classes,
FMX.StdCtrls;
type
{ @abstract(Appends formatted @link(TLogItem) to a TMemo in a VCL application) }
TFMXMemoLogAppender = class(TLoggerProAppenderBase)
private
FMemo: TMemo;
FMaxLogLines: Word;
FClearOnStartup: Boolean;
public
constructor Create(aMemo: TMemo; aMaxLogLines: Word = 100; aClearOnStartup: Boolean = False); reintroduce;
procedure Setup; override;
procedure TearDown; override;
procedure WriteLog(const aLogItem: TLogItem); override;
end;
implementation
uses
System.SysUtils,
Winapi.Windows,
Winapi.Messages;
const
DEFAULT_LOG_FORMAT = '%0:s [TID %1:-8d][%2:-10s] %3:s [%4:s]';
{ TVCLMemoLogAppender }
constructor TFMXMemoLogAppender.Create(aMemo: TMemo; aMaxLogLines: Word; aClearOnStartup: Boolean);
begin
inherited Create;
FMemo := aMemo;
FMaxLogLines := aMaxLogLines;
FClearOnStartup := aClearOnStartup;
end;
procedure TFMXMemoLogAppender.Setup;
begin
if FClearOnStartup then
begin
TThread.Synchronize(nil,
procedure
begin
FMemo.Clear;
end);
end;
end;
procedure TFMXMemoLogAppender.TearDown;
begin
// do nothing
end;
procedure TFMXMemoLogAppender.WriteLog(const aLogItem: TLogItem);
var
lText: string;
begin
lText := Format(DEFAULT_LOG_FORMAT, [datetimetostr(aLogItem.TimeStamp), aLogItem.ThreadID, aLogItem.LogTypeAsString, aLogItem.LogMessage,
aLogItem.LogTag]);
TThread.Queue(nil,
procedure
begin
FMemo.Lines.BeginUpdate;
try
if FMemo.Lines.Count = FMaxLogLines then
FMemo.Lines.Delete(0);
FMemo.Lines.Add(lText)
finally
FMemo.Lines.EndUpdate;
end;
SendMessage(FMemo.Handle, EM_SCROLLCARET, 0, 0);
end);
end;
end.
The text was updated successfully, but these errors were encountered: