Skip to content

Commit

Permalink
Samples refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
danieleteti committed Oct 24, 2017
1 parent 279686d commit 34134d4
Show file tree
Hide file tree
Showing 16 changed files with 547 additions and 474 deletions.
6 changes: 3 additions & 3 deletions LoggerPro.RedisAppender.pas
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ TLoggerProRedisAppender = class(TLoggerProAppenderBase)
FLogKeyPrefix: string;
FMaxSize: Int64;
public
constructor Create(aRedis: IRedisClient; aMaxSize: Int64 = 5000; aKeyPrefix: String = 'lplogs'); reintroduce;
constructor Create(aRedis: IRedisClient; aMaxSize: Int64 = 5000; aKeyPrefix: string = 'loggerpro'); reintroduce;
procedure Setup; override;
procedure TearDown; override;
procedure WriteLog(const aLogItem: TLogItem); override;
Expand All @@ -36,7 +36,7 @@ implementation
const
DEFAULT_LOG_FORMAT = '%0:s [TID %1:-8d][%2:-8s] %3:s [%4:s]';

constructor TLoggerProRedisAppender.Create(aRedis: IRedisClient; aMaxSize: Int64; aKeyPrefix: String);
constructor TLoggerProRedisAppender.Create(aRedis: IRedisClient; aMaxSize: Int64; aKeyPrefix: string);
begin
inherited Create;
FRedis := aRedis;
Expand Down Expand Up @@ -77,7 +77,7 @@ procedure TLoggerProRedisAppender.WriteLog(const aLogItem: TLogItem);
lText := Format(DEFAULT_LOG_FORMAT, [datetimetostr(aLogItem.TimeStamp),
aLogItem.ThreadID, aLogItem.LogTypeAsString, aLogItem.LogMessage,
aLogItem.LogTag]);
lKey := FLogKeyPrefix + '::' + aLogItem.LogTypeAsString.ToLower;
lKey := FLogKeyPrefix + '::logs'; // + aLogItem.LogTypeAsString.ToLower;
// Push the log item to the right of the list (logs:info, logs:warning, log:error)
FRedis.RPUSH(lKey, [lText]);
// Trim the list to the FMaxSize last elements
Expand Down
5 changes: 0 additions & 5 deletions LoggerPro.pas
Original file line number Diff line number Diff line change
Expand Up @@ -296,11 +296,6 @@ function BuildLogWriter(aAppenders: array of ILogAppender;
end;
Result := TLogWriter.Create(lLogAppenders, aLogLevel);
TLogWriter(Result).Initialize(aEventsHandlers);

// while not TLogWriter(Result).FLoggerThread.Started do
// begin
// sleep(1); // wait the thread start
// end;
end;

{ TLogger.TLogWriter }
Expand Down
4 changes: 3 additions & 1 deletion samples/50_custom_appender/LoggerProConfig.pas
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ procedure TMyCustomAppender.TearDown;
procedure TMyCustomAppender.WriteLog(const aLogItem: TLogItem);
begin
// uncomment this to see what happend if an appender raise an exception

// raise Exception.Create('Kill LoggerPro');

// uncomment this to see what happend if an appender is slow
Expand All @@ -51,7 +52,8 @@ procedure TMyCustomAppender.WriteLog(const aLogItem: TLogItem);

initialization

_Log := BuildLogWriter([TLoggerProConsoleAppender.Create,
_Log := BuildLogWriter([
TLoggerProConsoleAppender.Create,
TMyCustomAppender.Create])

end.
383 changes: 208 additions & 175 deletions samples/50_custom_appender/custom_appender.dproj

Large diffs are not rendered by default.

15 changes: 12 additions & 3 deletions samples/60_logging_inside_dll/MainFormU.dfm
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ object Form5: TForm5
Left = 0
Top = 0
Caption = 'Form5'
ClientHeight = 138
ClientWidth = 172
ClientHeight = 299
ClientWidth = 413
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Expand All @@ -24,11 +24,20 @@ object Form5: TForm5
end
object Button2: TButton
Left = 8
Top = 71
Top = 167
Width = 153
Height = 57
Caption = 'UnLoad Library'
TabOrder = 1
OnClick = Button2Click
end
object btnDoSomething: TButton
Left = 8
Top = 88
Width = 153
Height = 57
Caption = 'Do Something'
TabOrder = 2
OnClick = btnDoSomethingClick
end
end
10 changes: 9 additions & 1 deletion samples/60_logging_inside_dll/MainFormU.pas
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ interface
TForm5 = class(TForm)
Button1: TButton;
Button2: TButton;
btnDoSomething: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure btnDoSomethingClick(Sender: TObject);
private
FHandle: NativeUInt;
{ Private declarations }
Expand All @@ -22,7 +24,7 @@ TForm5 = class(TForm)

var
Form5: TForm5;
Init, DeInit: procedure;
Init, DeInit, DoSomething: procedure;

implementation

Expand All @@ -32,12 +34,18 @@ implementation
{$R *.dfm}


procedure TForm5.btnDoSomethingClick(Sender: TObject);
begin
DoSomething;
end;

procedure TForm5.Button1Click(Sender: TObject);
begin
Log.Debug('Loading dll', 'main');
FHandle := LoadLibrary('mydll.dll');
Init := GetProcAddress(FHandle, 'Init');
DeInit := GetProcAddress(FHandle, 'DeInit');
DoSomething := GetProcAddress(FHandle, 'DoSomething');
Init();
end;

Expand Down
10 changes: 5 additions & 5 deletions samples/60_logging_inside_dll/MyThreadU.pas
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ TMyThread = class(TThread)
['{603F3B5A-116C-4286-B70B-85CD7747BCF0}']
end;

TMyObject = class(TinterfacedObject, IMyInterface)
TMyObject = class(TInterfacedObject, IMyInterface)
protected
FMyThread: TMyThread;
fMyThread: TMyThread;
public
constructor Create;
destructor Destroy; override;
Expand All @@ -33,7 +33,7 @@ procedure TMyThread.Execute;
begin
while not Terminated do
begin
Log.Debug('Into the thread...', 'dll');
Log.Debug('Into the thread...', 'DLLTHREAD');
Sleep(1000);
end;
end;
Expand All @@ -43,14 +43,14 @@ procedure TMyThread.Execute;
constructor TMyObject.Create;
begin
inherited;
Log.Debug('Creating the thread', 'dll');
Log.Debug('Creating the thread', 'DLLTHREAD');
FMyThread := TMyThread.Create(true);
FMyThread.Start;
end;

destructor TMyObject.Destroy;
begin
Log.Debug('Destroing the thread', 'dll');
Log.Debug('Destroing the thread', 'DLLTHREAD');
FMyThread.Terminate;
FMyThread.WaitFor;
FMyThread.Free;
Expand Down
7 changes: 6 additions & 1 deletion samples/60_logging_inside_dll/mydll.dpr
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,13 @@ begin
ReleaseGlobalLogger; // This is required inside dll and ISAPI!!
end;

procedure DoSomething;
begin
Log.Debug('This is a log message from the DLL', 'DLL');
end;

exports
Init, DeInit;
Init, DeInit, DoSomething;

begin

Expand Down
Loading

0 comments on commit 34134d4

Please sign in to comment.