-
Notifications
You must be signed in to change notification settings - Fork 1
/
adtlog.pas.mcp
107 lines (83 loc) · 2.74 KB
/
adtlog.pas.mcp
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
106
107
(* This file is a part of the PascalAdt library, which provides
commonly used algorithms and data structures for the fpc and
Delphi compilers.
Copyright (C) 2004 by Lukasz Czajka
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public License
as published by the Free Software Foundation; either version 2.1 of
the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
02110-1301 USA *)
unit adtlog;
{ This unit provides logging facilities. All routines here work only
when compiled in the debug mode, otherwise they do nothing. }
interface
uses
SysUtils, Classes;
&include adtdefs.inc
const
pascal_adt_log_file_name = 'pascaladt.log';
{ sets <newstream> to be the current logging stream. The old logging
stream is destroyed; }
procedure SetLogStream(newstream : TStream);
{ Writes a specified message to the logging stream; appends newline; }
procedure WriteLogStream(const msg : String);
{ Opens pascal_adt_log_file_name as a log stream. Makes a backup if
this file exists. Destroys the previous stream. }
procedure OpenLogStream;
implementation
var
logStream : TStream;
{ this function is not present in Delphi }
procedure WriteByte(b : Byte);
begin
logStream.Write(b, 1);
end;
procedure SetLogStream(newstream : TStream);
begin
if newstream <> nil then
begin
logStream.Free;
logStream := newstream;
end;
end;
procedure WriteLogStream(const msg : string);
begin
if logStream <> nil then
begin
with logStream do
begin
Write((@msg[1])^, Length(msg));
{$ifdef PASCAL_ADT_WINDOWS }
WriteByte(13);
{$endif }
WriteByte(10);
end;
end;
end;
procedure OpenLogStream;
begin
logStream.Free;
if FileExists(pascal_adt_log_file_name) then
begin
if FileExists(pascal_adt_log_file_name + '.bak') then
DeleteFile(pascal_adt_log_file_name + '.bak');
RenameFile(pascal_adt_log_file_name, pascal_adt_log_file_name + '.bak');
end;
logStream := TFileStream.Create(pascal_adt_log_file_name,
fmCreate);
end;
initialization
logStream := nil;
{$ifdef DEBUG_PASCAL_ADT }
OpenLogStream;
{$endif DEBUG_PASCAL_ADT }
finalization
logStream.Free;
end.