client-log
This commit is contained in:
parent
0a79639aa8
commit
ea0ed85bbf
69
lms_cgi.lpr
69
lms_cgi.lpr
@ -4,7 +4,7 @@ program lms_cgi;
|
|||||||
|
|
||||||
uses
|
uses
|
||||||
Interfaces, Classes, SysUtils, inifiles, httpDefs, fpweb, custweb, custcgi,
|
Interfaces, Classes, SysUtils, inifiles, httpDefs, fpweb, custweb, custcgi,
|
||||||
lnetbase, tcpClient, tcpthreadhelper, extTypes;
|
lnetbase, tcpClient, tcpthreadhelper, extTypes, eventlog;
|
||||||
|
|
||||||
Type
|
Type
|
||||||
|
|
||||||
@ -33,13 +33,17 @@ Type
|
|||||||
flogFolder: string;
|
flogFolder: string;
|
||||||
fHost: string;
|
fHost: string;
|
||||||
fPort: integer;
|
fPort: integer;
|
||||||
|
flogger: TEventLog;
|
||||||
procedure LoadConfig;
|
procedure LoadConfig;
|
||||||
Protected
|
Protected
|
||||||
function InitializeWebHandler: TWebHandler; override;
|
function InitializeWebHandler: TWebHandler; override;
|
||||||
public
|
public
|
||||||
|
constructor CreateWithLogger(AOwner: TComponent);
|
||||||
|
destructor Destroy; override;
|
||||||
property Host: string read fHost;
|
property Host: string read fHost;
|
||||||
property Port: integer read fPort;
|
property Port: integer read fPort;
|
||||||
property LogFolder: string read fLogFolder;
|
property LogFolder: string read fLogFolder;
|
||||||
|
property Logger: TEventLog read flogger;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
const
|
const
|
||||||
@ -106,7 +110,34 @@ log(mtDebug,self,'Command '+ARequest.Command);
|
|||||||
LogStrings(mtInfo, @log,self,'CookieFields',Arequest.CookieFields);
|
LogStrings(mtInfo, @log,self,'CookieFields',Arequest.CookieFields);
|
||||||
LogStrings(mtInfo, @log,self,'CustomHeaders',Arequest.CustomHeaders);
|
LogStrings(mtInfo, @log,self,'CustomHeaders',Arequest.CustomHeaders);
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
|
if ARequest.QueryFields.Values['action']='cgi-test' then
|
||||||
|
begin
|
||||||
|
AResponse.ContentType := 'text/html';
|
||||||
|
AResponse.Contents.add('<h2>QueryFields</h2>');
|
||||||
|
AResponse.Contents.add('<dl>');
|
||||||
|
for i := 0 to ARequest.QueryFields.Count-1 do
|
||||||
|
begin
|
||||||
|
k := ARequest.QueryFields.Names[i];
|
||||||
|
v := ARequest.QueryFields.Values[k];
|
||||||
|
AResponse.Contents.add(format('<dt>%s</dt><dd>%s</dd>',[k,v]));
|
||||||
|
|
||||||
|
end;
|
||||||
|
AResponse.Contents.add('</dl>');
|
||||||
|
AResponse.Contents.add('');
|
||||||
|
AResponse.Contents.add('<h2>ContentFields</h2>');
|
||||||
|
AResponse.Contents.add('<dl>');
|
||||||
|
for i := 0 to ARequest.ContentFields.Count-1 do
|
||||||
|
begin
|
||||||
|
k := ARequest.ContentFields.Names[i];
|
||||||
|
v := ARequest.ContentFields.Values[k];
|
||||||
|
AResponse.Contents.add(format('<dt>%s</dt><dd>%s</dd>',[k,v]));
|
||||||
|
|
||||||
|
end;
|
||||||
|
AResponse.Contents.add('</dl>');
|
||||||
|
AResponse.Contents.add('');
|
||||||
|
AResponse.SendContent;
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
allfields := TStringList.Create;
|
allfields := TStringList.Create;
|
||||||
try
|
try
|
||||||
allfields.AddStrings(ARequest.QueryFields);
|
allfields.AddStrings(ARequest.QueryFields);
|
||||||
@ -164,18 +195,14 @@ var
|
|||||||
f: TextFile;
|
f: TextFile;
|
||||||
s: string;
|
s: string;
|
||||||
begin
|
begin
|
||||||
if (Owner as TMyCGIApp).LogFolder='' then exit;
|
if (Owner as TMyCGIApp).Logger=nil then exit;
|
||||||
case ALevel of
|
case ALevel of
|
||||||
mtError: s := '!!ERROR: ';
|
mtError: (Owner as TMyCGIApp).Logger.Error(msg);
|
||||||
mtWarning: s := '!WARNING: ';
|
mtWarning: (Owner as TMyCGIApp).Logger.Warning(msg);
|
||||||
mtInfo: s := #09;
|
mtInfo: (Owner as TMyCGIApp).Logger.Info(msg);
|
||||||
mtDebug: s := #09#09;
|
mtDebug: (Owner as TMyCGIApp).Logger.Debug(msg);
|
||||||
mtExtra: s := #09#09#09;
|
mtExtra: (Owner as TMyCGIApp).Logger.Log(msg);
|
||||||
end;
|
end;
|
||||||
assignfile(f, (Owner as TMyCGIApp).LogFolder);
|
|
||||||
if fileexists((Owner as TMyCGIApp).LogFolder) then append(f) else rewrite(f);
|
|
||||||
writeln(f,s+msg);
|
|
||||||
closefile(f);
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TMyCGIApp.LoadConfig;
|
procedure TMyCGIApp.LoadConfig;
|
||||||
@ -195,13 +222,31 @@ end;
|
|||||||
function TMyCGIApp.InitializeWebHandler: TWebHandler;
|
function TMyCGIApp.InitializeWebHandler: TWebHandler;
|
||||||
begin
|
begin
|
||||||
LoadConfig;
|
LoadConfig;
|
||||||
|
flogger.FileName:=LogFolder;
|
||||||
|
flogger.Active:=true;
|
||||||
|
flogger.Info('start');
|
||||||
Result:=TMyCgiHandler.Create(self);
|
Result:=TMyCgiHandler.Create(self);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
constructor TMyCGIApp.CreateWithLogger(AOwner: TComponent);
|
||||||
|
begin
|
||||||
|
flogger := TEventLog.Create(self);
|
||||||
|
flogger.Identification:='lms_cgi_client';
|
||||||
|
flogger.LogType:={$IFDEF LINUX}ltSystem{$ELSE}ltFile{$ENDIF};
|
||||||
|
inherited Create(AOwner);
|
||||||
|
|
||||||
|
end;
|
||||||
|
|
||||||
|
destructor TMyCGIApp.Destroy;
|
||||||
|
begin
|
||||||
|
flogger.free;
|
||||||
|
inherited Destroy;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
begin
|
begin
|
||||||
with TMyCGIApp.create(nil) do
|
with TMyCGIApp.CreateWithLogger(nil) do
|
||||||
try
|
try
|
||||||
Initialize;
|
Initialize;
|
||||||
Run;
|
Run;
|
||||||
|
BIN
lms_cgi.obj
BIN
lms_cgi.obj
Binary file not shown.
Loading…
Reference in New Issue
Block a user