-
Notifications
You must be signed in to change notification settings - Fork 0
/
dtinylogger.pas
96 lines (83 loc) · 1.71 KB
/
dtinylogger.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
unit dtinylogger;
// Tiny session logger. rlyeh, public domain | wtrmrkrlyeh
// Pascal port by Doj
{$MODE OBJFPC}
{$MODESWITCH ADVANCEDRECORDS}
{$MODESWITCH DEFAULTPARAMETERS}
{$MODESWITCH OUT}
{$MODESWITCH RESULT}
interface
type
TLogger = record
procedure Init;
procedure Done;
private
Buffer: array[0 .. 16 * 1024 - 1] of Byte;
{$IF FPC_FULLVERSION > 30101}
Initialized: Boolean;
class operator Initialize(var Logger: TLogger);
class operator Finalize(var Logger: TLogger);
{$ENDIF}
end;
implementation
procedure TLogger.Init;
begin
{$IF FPC_FULLVERSION > 30101}
if Initialized then
Exit;
Initialized := True;
{$ENDIF}
{$IF Defined(SHIPPING)}
Close(output);
{$ELSE}
{$IF Defined(PSVITA)}
Assign(output, 'host0://log_vita.txt');
{$ELSEIF Defined(PS3)}
Assign(output, '/app_home/log_ps3.txt');
{$ELSEIF Defined(PS4)}
Assign(output, '/hostapp/log_ps4.txt');
{$ELSE}
Assign(output, 'log_desktop.txt');
{$ENDIF}
{$PUSH}{$I-} Append(output); {$POP}
if IOResult <> 0 then
ReWrite(output);
// Flush automatically every 16 KiB from now
SetTextBuf(output, Buffer[0], Length(Buffer));
// Header
Writeln(';; New session');
Flush(output);
{$ENDIF}
end;
procedure TLogger.Done;
begin
{$IF FPC_FULLVERSION > 30101}
if not Initialized then
Exit;
Initialized := False;
{$ENDIF}
{$IF not Defined(SHIPPING)}
Flush(output);
{$ENDIF}
end;
{$IF FPC_FULLVERSION > 30101}
class operator TLogger.Initialize(var Logger: TLogger);
begin
Logger.Initialized := False;
Logger.Init;
end;
class operator TLogger.Finalize(var Logger: TLogger);
begin
Logger.Done;
end;
{$ENDIF}
//
// var
// resident: TLogger;
// begin
// resident.Init;
// Writeln("hello world");
// resident.Done
// end;
//
end.