-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtislogging.pas
More file actions
76 lines (64 loc) · 2.11 KB
/
tislogging.pas
File metadata and controls
76 lines (64 loc) · 2.11 KB
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
unit tislogging;
{ -----------------------------------------------------------------------
# This file is part of WAPT
# Copyright (C) 2013 Tranquil IT Systems http://www.tranquil.it
# WAPT aims to help Windows systems administrators to deploy
# setup and update applications on users PC.
#
# Part of this file is based on JEDI JCL library
#
# WAPT is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# WAPT 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with WAPT. If not, see <http://www.gnu.org/licenses/>.
#
# -----------------------------------------------------------------------
}
interface
uses
Classes, SysUtils {$ifdef windows},Windows{$endif};
type LogLevel=(DEBUG, INFO, WARNING, ERROR, CRITICAL);
const StrLogLevel: array[DEBUG..CRITICAL] of String = ('DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL');
procedure Logger(Msg:String;level:LogLevel=WARNING);
procedure ODS(Msg:String);
var
loghook : procedure(logmsg:String) of object;
const
currentLogLevel:LogLevel=WARNING;
implementation
procedure Logger(Msg: String;level:LogLevel=WARNING);
begin
if level>=currentLogLevel then
begin
if Assigned(loghook) then
loghook(Msg)
else if IsConsole then
WriteLn(Format('%s [%s] %s',[FormatDateTime('YYYY-mm-dd hh:nn:ss',Now),StrLogLevel[level],Msg]));
{$ifdef windows}
if level=DEBUG then
ODS(Msg);
{$endif}
end;
end;
{$ifdef windows}
procedure ODS(Msg:String);
var
umsg: UnicodeString;
begin
umsg := UTF8Decode(msg);
OutputDebugStringW(PWideChar(umsg));
end;
{$else}
procedure ODS(Msg:String);
begin
end;
{$endif}
end.