forked from andremussche/DelphiWebsockets
-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
WSDebugger.pas
105 lines (96 loc) · 2.99 KB
/
WSDebugger.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
unit WSDebugger;
interface
{$IF DEFINED(DEBUG) OR DEFINED(DEBUG_WS) OR DEFINED(CHECKSPEED)}
uses
{$IF DEFINED(MSWINDOWS)}
Winapi.Windows,
{$ENDIF}
System.SysUtils;
{$ENDIF}
/// <summary>Helps in debugging. If WS_DEBUG is not defined, this is a NO-OP as
/// all the code are IF DEFINED out.</summary>
procedure OutputDebugString(const ARoleName, AMsg: string); overload; {$IF NOT DEFINED(WS_DEBUG)} inline; {$ENDIF}
/// <summary>Helps in debugging. If WS_DEBUG is not defined, this is a NO-OP as
/// all the code are IF DEFINED out.</summary>
procedure OutputDebugString(const AMsg: string); overload;
procedure OutputDebugString(Number: Integer; Elapsed: Int64); overload;
implementation
uses
System.Classes,
{$IF DEFINED(ANDROID)}
FMX.Platform, FMX.Platform.Logger.Android.Fix,
{$ENDIF}
System.SyncObjs;
procedure OutputDebugString(const ARoleName, AMsg: string);
begin
{$IF DEFINED(DEBUG) OR DEFINED(DEBUG_WS) OR DEFINED(CHECKSPEED)}
var
LMsg: string;
{$ENDIF}
{$IF DEFINED(DEBUG) OR DEFINED(DEBUG_WS) OR DEFINED(CHECKSPEED)}
var LDateTime := FormatDateTime('hh:nn:ss', Now);
{$IF DEFINED(MSWINDOWS)}
LMsg := Format('%s - %s - %s', [LDateTime, ARoleName, AMsg]);
Winapi.Windows.OutputDebugString(PChar(LMsg));
{$ENDIF}
{$IF DEFINED(ANDROID)}
LMsg := Format('%s - %s', [ARoleName, AMsg]);
var LLogService: IFMXLoggingService;
if TPlatformServices.Current.SupportsPlatformService(IFMXLoggingService, LLogService) then
begin
var LTagService: IFMXTagPriority;
if Supports(LLogService, IFMXTagPriority, LTagService) then
LTagService.d(ARoleName, LMsg) else
LLogService.Log('%s', [LMsg]);
end;
{$ENDIF}
{$ENDIF}
end;
procedure OutputDebugString(const AMsg: string);
{$IF DEFINED(DEBUG)}
var
LDateTime, LMsg: string;
{$IF DEFINED(ANDROID)}
LLogService: IFMXLoggingService;
{$ENDIF}
{$ENDIF}
begin
{$IF DEFINED(DEBUG) OR DEFINED(DEBUG_WS) OR DEFINED(CHECKSPEED)}
LDateTime := FormatDateTime('hh:nn:ss', Now);
LMsg := Format('%s - %s', [LDateTime, AMsg]);
{$IF DEFINED(MSWINDOWS) OR DEFINED(DEBUG_WS)}
Winapi.Windows.OutputDebugString(PChar(LMsg));
{$ENDIF}
{$IF DEFINED(ANDROID)}
if TPlatformServices.Current.SupportsPlatformService(IFMXLoggingService, LLogService) then
begin
LLogService.Log('%s', [LMsg]);
end;
{$ENDIF}
{$ENDIF}
end;
procedure OutputDebugString(Number: Integer; Elapsed: Int64);
{$IF DEFINED(DEBUG) OR DEFINED(DEBUG_WS) OR DEFINED(CHECKSPEED)}
var
LMsg: string;
{$IF DEFINED(ANDROID)}
LLogService: IFMXLoggingService;
{$ENDIF}
{$ENDIF}
begin
if Elapsed < 500 then
Exit;
{$IF DEFINED(DEBUG) OR DEFINED(DEBUG_WS) OR DEFINED(CHECKSPEED)}
LMsg := Format('%d: %d', [Number, Elapsed]);
{$IF DEFINED(MSWINDOWS) OR DEFINED(DEBUG_WS)}
Winapi.Windows.OutputDebugString(PChar(LMsg));
{$ENDIF}
{$IF DEFINED(ANDROID)}
if TPlatformServices.Current.SupportsPlatformService(IFMXLoggingService, LLogService) then
begin
LLogService.Log('%s', [LMsg]);
end;
{$ENDIF}
{$ENDIF}
end;
end.