2007-07-07 20:56:01 +00:00
|
|
|
{
|
|
|
|
This file is part of the Web Service Toolkit
|
2014-05-03 16:34:30 +00:00
|
|
|
Copyright (c) 2007-2014 by Inoussa OUEDRAOGO
|
2007-07-07 20:56:01 +00:00
|
|
|
|
|
|
|
This file is provide under modified LGPL licence
|
|
|
|
( the files COPYING.modifiedLGPL and COPYING.LGPL).
|
|
|
|
|
|
|
|
|
|
|
|
This program 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.
|
|
|
|
}
|
2007-09-02 19:05:47 +00:00
|
|
|
{$INCLUDE wst_global.inc}
|
2007-06-24 23:33:51 +00:00
|
|
|
unit logger_intf;
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
|
|
|
Classes, SysUtils;
|
|
|
|
|
|
|
|
type
|
|
|
|
|
2014-12-04 13:11:07 +00:00
|
|
|
TMessageType = ( mtInfo, mtWarning, mtError );
|
2007-06-24 23:33:51 +00:00
|
|
|
|
|
|
|
const
|
2014-12-04 13:11:07 +00:00
|
|
|
MessageTypeNames : array[TMessageType] of string = (
|
|
|
|
'Information', 'Warning', 'Error'
|
|
|
|
);
|
2007-06-24 23:33:51 +00:00
|
|
|
|
|
|
|
type
|
|
|
|
|
2014-12-04 13:11:07 +00:00
|
|
|
TOnLogMessageEvent = procedure (const AMsgType : TMessageType; const AMsg : string) of object;
|
|
|
|
|
2007-06-24 23:33:51 +00:00
|
|
|
ILogger = interface
|
|
|
|
['{158C90B5-BAC3-40A1-B471-C9327692A3BF}']
|
|
|
|
procedure Log(const AMsgType : TMessageType; const AMsg : string);overload;
|
|
|
|
procedure Log(const AMsgType : TMessageType; const AMsg : string; const AArgs : array of const);overload;
|
|
|
|
function GetMessageCount(const AMsgType : TMessageType) : Integer;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{ TSimpleConsoleLogger }
|
|
|
|
|
|
|
|
TSimpleConsoleLogger = class(TInterfacedObject,ILogger)
|
|
|
|
private
|
|
|
|
FMessageCount : array[TMessageType] of Integer;
|
|
|
|
protected
|
|
|
|
procedure Log(const AMsgType : TMessageType; const AMsg : string);overload;
|
|
|
|
procedure Log(const AMsgType : TMessageType; const AMsg : string; const AArgs : array of const);overload;
|
|
|
|
function GetMessageCount(const AMsgType : TMessageType) : Integer;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2009-03-13 17:10:21 +00:00
|
|
|
function HasLogger() : Boolean;
|
|
|
|
function SetLogger(ALogger : ILogger) : ILogger;
|
|
|
|
function GetLogger() : ILogger;
|
2007-06-24 23:33:51 +00:00
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
var FLogger : ILogger = nil;
|
|
|
|
function SetLogger(ALogger : ILogger) : ILogger;
|
|
|
|
begin
|
|
|
|
Result := FLogger;
|
|
|
|
FLogger := ALogger;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function GetLogger() : ILogger;
|
|
|
|
begin
|
|
|
|
Result := FLogger;
|
|
|
|
end;
|
|
|
|
|
2007-09-09 22:30:50 +00:00
|
|
|
function HasLogger() : Boolean;
|
|
|
|
begin
|
|
|
|
Result := Assigned(FLogger);
|
|
|
|
end;
|
|
|
|
|
2007-06-24 23:33:51 +00:00
|
|
|
{ TSimpleConsoleLogger }
|
|
|
|
|
|
|
|
procedure TSimpleConsoleLogger.Log(const AMsgType: TMessageType; const AMsg: string);
|
|
|
|
begin
|
|
|
|
Log(AMsgType,AMsg,[]);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TSimpleConsoleLogger.Log(
|
|
|
|
const AMsgType : TMessageType;
|
|
|
|
const AMsg : string;
|
|
|
|
const AArgs : array of const
|
|
|
|
);
|
|
|
|
begin
|
|
|
|
Inc(FMessageCount[AMsgType]);
|
|
|
|
WriteLn(Format('%s : %s',[MessageTypeNames[AMsgType],Format(AMsg,AArgs)]));
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TSimpleConsoleLogger.GetMessageCount(const AMsgType: TMessageType): Integer;
|
|
|
|
begin
|
|
|
|
Result := FMessageCount[AMsgType];
|
|
|
|
end;
|
|
|
|
|
|
|
|
end.
|
|
|
|
|