Skip to content

Commit

Permalink
Merge pull request #30 from adrianosantostreina/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
adrianosantostreina authored Aug 20, 2024
2 parents 9c3b10c + 3ea116c commit db4333a
Show file tree
Hide file tree
Showing 9 changed files with 191 additions and 12 deletions.
18 changes: 15 additions & 3 deletions MultiLog4D.groupproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
<Projects Include="Samples\# Default Sample\DefaultSample.dproj">
<Dependencies/>
</Projects>
<Projects Include="D:\Downloads\Logger\Logger.dproj">
<Dependencies/>
</Projects>
</ItemGroup>
<ProjectExtensions>
<Borland.Personality>Default.Personality.12</Borland.Personality>
Expand All @@ -35,14 +38,23 @@
<Target Name="DefaultSample:Make">
<MSBuild Projects="Samples\# Default Sample\DefaultSample.dproj" Targets="Make"/>
</Target>
<Target Name="Logger">
<MSBuild Projects="D:\Downloads\Logger\Logger.dproj"/>
</Target>
<Target Name="Logger:Clean">
<MSBuild Projects="D:\Downloads\Logger\Logger.dproj" Targets="Clean"/>
</Target>
<Target Name="Logger:Make">
<MSBuild Projects="D:\Downloads\Logger\Logger.dproj" Targets="Make"/>
</Target>
<Target Name="Build">
<CallTarget Targets="AndroidMultiLog4D;DefaultSample"/>
<CallTarget Targets="AndroidMultiLog4D;DefaultSample;Logger"/>
</Target>
<Target Name="Clean">
<CallTarget Targets="AndroidMultiLog4D:Clean;DefaultSample:Clean"/>
<CallTarget Targets="AndroidMultiLog4D:Clean;DefaultSample:Clean;Logger:Clean"/>
</Target>
<Target Name="Make">
<CallTarget Targets="AndroidMultiLog4D:Make;DefaultSample:Make"/>
<CallTarget Targets="AndroidMultiLog4D:Make;DefaultSample:Make;Logger:Make"/>
</Target>
<Import Project="$(BDS)\Bin\CodeGear.Group.Targets" Condition="Exists('$(BDS)\Bin\CodeGear.Group.Targets')"/>
</Project>
2 changes: 1 addition & 1 deletion Samples/# Default Sample/DefaultSample.dproj
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,6 @@
<VerInfo_IncludeVerInfo>true</VerInfo_IncludeVerInfo>
<VerInfo_UIDeviceFamily>iPhoneAndiPad</VerInfo_UIDeviceFamily>
<VerInfo_BundleId>br.com.adrianosantostreina.MultiLog4D</VerInfo_BundleId>
<DCC_UnitSearchPath>..\..\src\;$(DCC_UnitSearchPath)</DCC_UnitSearchPath>
<PF_DevDebug>Apple Development: adrianosantospro@gmail.com (S885332266)</PF_DevDebug>
<PF_MobileProvisionDebug>5fc1969e-d5d3-4879-8e09-662994259d2c</PF_MobileProvisionDebug>
<PF_AutoMobileProvisionDebug>False</PF_AutoMobileProvisionDebug>
Expand All @@ -380,6 +379,7 @@
<AppDPIAwarenessMode>PerMonitorV2</AppDPIAwarenessMode>
<VerInfo_IncludeVerInfo>true</VerInfo_IncludeVerInfo>
<VerInfo_Locale>1033</VerInfo_Locale>
<DCC_Define>ML4D_SERVICE;$(DCC_Define)</DCC_Define>
</PropertyGroup>
<PropertyGroup Condition="'$(Cfg_1_Win64)'!=''">
<AppDPIAwarenessMode>PerMonitorV2</AppDPIAwarenessMode>
Expand Down
11 changes: 11 additions & 0 deletions Samples/# Default Sample/Unit1.fmx
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,15 @@ object Form1: TForm1
TabOrder = 10
Text = 'Fatal Error'
end
object Button7: TButton
Position.X = 16.000000000000000000
Position.Y = 370.000000000000000000
Size.Width = 161.000000000000000000
Size.Height = 43.000000000000000000
Size.PlatformDefault = False
TabOrder = 12
Text = 'LogViewer'
TextSettings.Trimming = None
OnClick = Button7Click
end
end
18 changes: 18 additions & 0 deletions Samples/# Default Sample/Unit1.pas
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ TForm1 = class(TForm)
radioWarning: TRadioButton;
radioError: TRadioButton;
radioFatalError: TRadioButton;
Button7: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
Expand All @@ -39,6 +40,7 @@ TForm1 = class(TForm)
procedure Button6Click(Sender: TObject);
procedure Button8Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button7Click(Sender: TObject);
private
{ Private declarations }
FCont: Integer;
Expand Down Expand Up @@ -126,6 +128,22 @@ procedure TForm1.Button6Click(Sender: TObject);
end;
end;

procedure TForm1.Button7Click(Sender: TObject);
begin
TMultiLog4DUtil
.Logger
.Tag('MultiLog4D')
{$IFDEF ML4D_SERVICE}
.Category(TEventCategory.ecNone)
.EventID(1)
{$ENDIF}
{$IFDEF MSWINDOWS}
//.UserName('Adriano Santos')
//.UserName(EmptyStr)
{$ENDIF}
.LogWriteFatalError('Teste4');
end;

procedure TForm1.Button8Click(Sender: TObject);
var
LTypeMsg : TLogType;
Expand Down
53 changes: 50 additions & 3 deletions src/MultiLog4D.Base.pas
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,39 @@ interface
{$IFDEF ANDROID}
,Androidapi.Helpers
{$ENDIF}

{$IFDEF MSWINDOWS}
,Winapi.Windows
{$ENDIF}
,MultiLog4D.Types,

MultiLog4D.Common,
MultiLog4D.Interfaces;

type
TMultiLog4DBase = class(TInterfacedObject, IMultiLog4D)
private

protected
class var FTag: string;
class var FTagSet: Boolean;
{$IFDEF MSWINDOWS}
FUserName: string;
{$ENDIF}
{$IFDEF ML4D_SERVICE}
FEventCategory: TEventCategory;
FEventID: DWORD;
function GetCategoryName: string;
{$ENDIF}
function GetDefaultTag: string;
protected
function GetLogPrefix(const ALogType: TLogType): string;
public
function Tag(const ATag: string): IMultiLog4D; virtual;
{$IFDEF ML4D_SERVICE}
function Category(const AEventCategory: TEventCategory): IMultiLog4D;
function EventID(const AEventID: DWORD): IMultiLog4D;
{$ENDIF}
{$IFDEF MSWINDOWS}
function UserName(const AUserName: string): IMultiLog4D;
{$ENDIF}
function LogWrite(const AMsg: string; const ALogType: TLogType): IMultiLog4D; virtual; abstract;
function LogWriteInformation(const AMsg: string): IMultiLog4D; virtual; abstract;
function LogWriteWarning(const AMsg: string): IMultiLog4D; virtual; abstract;
Expand Down Expand Up @@ -52,6 +69,36 @@ function TMultiLog4DBase.Tag(const ATag: string): IMultiLog4D;
Result := Self as IMultiLog4D;
end;

{$IFDEF ML4D_SERVICE}
function TMultiLog4DBase.GetCategoryName: string;
begin
Result := EventCategoryNames[FEventCategory];
end;

function TMultiLog4DBase.Category(const AEventCategory: TEventCategory): IMultiLog4D;
begin
FEventCategory := AEventCategory;
Result := Self;
end;

function TMultiLog4DBase.EventID(const AEventID: DWORD): IMultiLog4D;
begin
FEventID := AEventID;
Result := Self;
end;
{$ENDIF}

{$IFDEF MSWINDOWS}
function TMultiLog4DBase.UserName(const AUserName: string): IMultiLog4D;
begin
if not AUserName.IsEmpty
then FUserName := AUserName
else FUserName := TMultiLog4DCommon.GetCurrentUserName;

Result := Self;
end;
{$ENDIF}

function TMultiLog4DBase.GetLogPrefix(const ALogType: TLogType): string;
begin
case ALogType of
Expand Down
31 changes: 29 additions & 2 deletions src/MultiLog4D.Factory.pas
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,23 @@ implementation

uses
{$IFDEF ANDROID}
MultiLog4D.Android;
MultiLog4D.Android,
{$ENDIF}
{$IFDEF IOS}
MultiLog4D.IOS;
MultiLog4D.IOS,
{$ENDIF}
{$IFDEF MSWINDOWS}
{$IFDEF CONSOLE}

{$ENDIF}

{$IFDEF FILE}

{$ENDIF}

{$IFDEF ML4D_SERVICE}
MultiLog4D.Windows.Services,
{$ENDIF}
{$ENDIF}
System.Classes;

Expand All @@ -40,8 +53,22 @@ class function TLogFactory.GetLogger: IMultiLog4D;
{$IFDEF IOS}
FLogger := TMultiLog4DiOS.Create;
{$ENDIF}
{$IFDEF MSWINDOWS}
{$IFDEF CONSOLE}

{$ENDIF}
{$IFDEF FILE}

{$ENDIF}

{$IFDEF ML4D_SERVICE}
FLogger := TMultiLog4DWindowsServices.Create;
{$ENDIF}
{$ENDIF}
end;

Result := FLogger;
end;


end.
12 changes: 12 additions & 0 deletions src/MultiLog4D.Interfaces.pas
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,24 @@ interface
System.StrUtils,
System.SysUtils,
System.Classes,
{$IFDEF MSWINDOWS}
{$IFDEF ML4D_SERVICE}
Winapi.Windows,
{$ENDIF}
{$ENDIF}
MultiLog4D.Types;

type
IMultiLog4D = interface
['{85313A35-9033-4179-8046-B22AD3E36E60}']
function Tag(const ATag: string): IMultiLog4D;
{$IFDEF ML4D_SERVICE}
function Category(const AEventCategory: TEventCategory): IMultiLog4D;
function EventID(const AEventID: DWORD): IMultiLog4D;
{$ENDIF}
{$IFDEF MSWINDOWS}
function UserName(const AUserName: string): IMultiLog4D;
{$ENDIF}
function LogWrite(const AMsg: string; const ALogType: TLogType): IMultiLog4D;
function LogWriteInformation(const AMsg: string): IMultiLog4D;
function LogWriteWarning(const AMsg: string): IMultiLog4D;
Expand Down
14 changes: 14 additions & 0 deletions src/MultiLog4D.Types.pas
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,20 @@ interface

type
TLogType = (ltInformation, ltWarning, ltError, ltFatalError);
TEventCategory = (ecNone, ecApplication, ecSecurity, ecPerformance, ecError, ecWarning, ecDebug, ecTransaction, ecNetwork);

const
EventCategoryNames: array[TEventCategory] of string = (
'None',
'Application',
'Security',
'Performance',
'Error',
'Warning',
'Debug',
'Transaction',
'Network'
);

implementation

Expand Down
44 changes: 41 additions & 3 deletions src/MultiLog4D.Util.pas
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@ interface
System.StrUtils,
System.SysUtils,
System.Classes,
{$IFDEF MSWINDOWS}
{$IFDEF ML4D_SERVICE}
Winapi.Windows,
{$ENDIF}
{$ENDIF}
MultiLog4D.Interfaces,
MultiLog4D.Factory;
MultiLog4D.Factory,
MultiLog4D.Types;

type
TMultiLog4DUtil = class
Expand All @@ -16,6 +22,13 @@ TMultiLog4DUtil = class
class constructor Create;
public
class function Logger: IMultiLog4D; static;
{$IFDEF ML4D_SERVICE}
class procedure SetCategory(const AEventCategory: TEventCategory); static;
class procedure SetEventID(const AEventID: DWORD); static;
{$ENDIF}
{$IFDEF MSWINDOWS}
class procedure SetUserName(const AUserName: string); static;
{$ENDIF}
end;

implementation
Expand All @@ -30,10 +43,35 @@ class function TMultiLog4DUtil.Logger: IMultiLog4D;
Result := FLogger;
end;

{$IFDEF ML4D_SERVICE}

class procedure TMultiLog4DUtil.SetCategory(const AEventCategory: TEventCategory);
begin
if Supports(FLogger, IMultiLog4D) then
(FLogger as IMultiLog4D).Category(AEventCategory);
end;

class procedure TMultiLog4DUtil.SetEventID(const AEventID: DWORD);
begin
if Supports(FLogger, IMultiLog4D) then
(FLogger as IMultiLog4D).EventID(AEventID);
end;
{$ENDIF}

{$IFDEF MSWINDOWS}
class procedure TMultiLog4DUtil.SetUserName(const AUserName: string);
begin
if Supports(FLogger, IMultiLog4D) then
(FLogger as IMultiLog4D).UserName(AUserName);
end;
{$ENDIF}

initialization
TMultiLog4DUtil.Create;

TMultiLog4DUtil.Create;

finalization
TMultiLog4DUtil.FLogger := nil;

TMultiLog4DUtil.FLogger := nil;

end.

0 comments on commit db4333a

Please sign in to comment.