Skip to content

Commit

Permalink
Sample projects
Browse files Browse the repository at this point in the history
  • Loading branch information
danieleteti committed Mar 25, 2016
1 parent 574ddb5 commit 5540787
Show file tree
Hide file tree
Showing 27 changed files with 3,129 additions and 19 deletions.
24 changes: 12 additions & 12 deletions LoggerPro.FileAppender.pas
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ interface
DEFAULT_MAX_FILE_SIZE_KB = 1000;

type
TLogFileAppender = class(TInterfacedObject, ILogAppender)
TLoggerProFileAppender = class(TInterfacedObject, ILogAppender)
private
FFormatSettings: TFormatSettings;
FWritersDictionary: TObjectDictionary<String, TStreamWriter>;
Expand Down Expand Up @@ -50,9 +50,9 @@ implementation
uses
System.IOUtils;

{ TLogFileAppender }
{ TLoggerProFileAppender }

function TLogFileAppender.GetLogFileName(const aTag: String;
function TLoggerProFileAppender.GetLogFileName(const aTag: String;
const aFileNumber: Integer): String;
var
lExt: string;
Expand All @@ -61,7 +61,7 @@ function TLogFileAppender.GetLogFileName(const aTag: String;
Result := ChangeFileExt(GetModuleName(HInstance), lExt);
end;

procedure TLogFileAppender.Setup;
procedure TLoggerProFileAppender.Setup;
begin
FFormatSettings.DateSeparator := '-';
FFormatSettings.TimeSeparator := ':';
Expand All @@ -71,19 +71,19 @@ procedure TLogFileAppender.Setup;
([doOwnsValues]);
end;

procedure TLogFileAppender.TearDown;
procedure TLoggerProFileAppender.TearDown;
begin
FWritersDictionary.Free;
end;

procedure TLogFileAppender.WriteLog(const aStreamWriter: TStreamWriter;
procedure TLoggerProFileAppender.WriteLog(const aStreamWriter: TStreamWriter;
const aValue: String);
begin
aStreamWriter.WriteLine(aValue);
aStreamWriter.Flush;
end;

procedure TLogFileAppender.WriteLog(const aLogItem: TLogItem);
procedure TLoggerProFileAppender.WriteLog(const aLogItem: TLogItem);
var
lWriter: TStreamWriter;
lLogFileName: string;
Expand All @@ -102,7 +102,7 @@ procedure TLogFileAppender.WriteLog(const aLogItem: TLogItem);
end;
end;

procedure TLogFileAppender.RetryMove(const aFileSrc, aFileDest: String);
procedure TLoggerProFileAppender.RetryMove(const aFileSrc, aFileDest: String);
var
lRetries: Integer;
const
Expand Down Expand Up @@ -131,7 +131,7 @@ procedure TLogFileAppender.RetryMove(const aFileSrc, aFileDest: String);
raise ELoggerPro.CreateFmt('Cannot rename %s to %s', [aFileSrc, aFileDest]);
end;

procedure TLogFileAppender.RotateLog(const aLogItem: TLogItem;
procedure TLoggerProFileAppender.RotateLog(const aLogItem: TLogItem;
lWriter: TStreamWriter);
var
lLogFileName: string;
Expand Down Expand Up @@ -163,15 +163,15 @@ procedure TLogFileAppender.RotateLog(const aLogItem: TLogItem;
WriteLog(lWriter, '#[START LOG ' + datetimetostr(Now, FFormatSettings) + ']');
end;

procedure TLogFileAppender.AddWriter(const aLogItem: TLogItem;
procedure TLoggerProFileAppender.AddWriter(const aLogItem: TLogItem;
var lWriter: TStreamWriter; var lLogFileName: string);
begin
lLogFileName := GetLogFileName(aLogItem.LogTag, 0);
lWriter := CreateWriter(lLogFileName);
FWritersDictionary.Add(aLogItem.LogTag, lWriter);
end;

constructor TLogFileAppender.Create(aMaxBackupFileCount: Integer;
constructor TLoggerProFileAppender.Create(aMaxBackupFileCount: Integer;
aMaxFileSizeInKiloByte: Integer; aLogFormat: String);
begin
inherited Create;
Expand All @@ -180,7 +180,7 @@ constructor TLogFileAppender.Create(aMaxBackupFileCount: Integer;
FLogFormat := aLogFormat;
end;

function TLogFileAppender.CreateWriter(const aFileName: String): TStreamWriter;
function TLoggerProFileAppender.CreateWriter(const aFileName: String): TStreamWriter;
var
lFileStream: TFileStream;
lFileAccessMode: Word;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
unit LoggerPro.DebugStringAppender;
unit LoggerPro.OutputDebugStringAppender;

interface

uses
LoggerPro, System.Classes;

type
TOutputDebugStringLogAppender = class(TInterfacedObject, ILogAppender)
TLoggerProOutputDebugStringAppender = class(TInterfacedObject, ILogAppender)
private
FStrings: TStrings;
FModuleName: string;
Expand All @@ -26,22 +26,22 @@ implementation
const
DEFAULT_LOG_FORMAT = '%0:s [TID %1:-8d][%2:-10s] %3:s [%4:s]';

constructor TOutputDebugStringLogAppender.Create;
constructor TLoggerProOutputDebugStringAppender.Create;
begin
inherited Create;
end;

procedure TOutputDebugStringLogAppender.Setup;
procedure TLoggerProOutputDebugStringAppender.Setup;
begin
FModuleName := TPath.GetFileName(GetModuleName(HInstance));
end;

procedure TOutputDebugStringLogAppender.TearDown;
procedure TLoggerProOutputDebugStringAppender.TearDown;
begin
// do nothing
end;

procedure TOutputDebugStringLogAppender.WriteLog(const aLogItem: TLogItem);
procedure TLoggerProOutputDebugStringAppender.WriteLog(const aLogItem: TLogItem);
var
lLog: string;
begin
Expand Down
2 changes: 1 addition & 1 deletion LoggerPro.pas
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class procedure TLogger.Initialize;
begin
if ConfiguredAppenders.Count = 0 then
begin
ConfiguredAppenders.Add(TLogFileAppender.Create);
ConfiguredAppenders.Add(TLoggerProFileAppender.Create);
end;

Instance := TLogWriter.Create(ConfiguredAppenders);
Expand Down
19 changes: 19 additions & 0 deletions samples/01_zero_conf_logging/LoggerProConfig.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
unit LoggerProConfig;

interface

implementation

uses
LoggerPro;

procedure SetupLogger;
begin
TLogger.Initialize;
end;

initialization

SetupLogger;

end.
15 changes: 15 additions & 0 deletions samples/01_zero_conf_logging/zero_conf_logging.dpr
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
program zero_conf_logging;

uses
Vcl.Forms,
MainFormU in '..\common\MainFormU.pas' {MainForm},
LoggerProConfig in 'LoggerProConfig.pas';

{$R *.res}

begin
Application.Initialize;
Application.MainFormOnTaskbar := True;
Application.CreateForm(TMainForm, MainForm);
Application.Run;
end.
Loading

0 comments on commit 5540787

Please sign in to comment.