00001 {*********************************************************}
00002 { }
00003 { Zeos Database Objects }
00004 { Database Logging Classes and Interfaces }
00005 { }
00006 { Originally written by Sergey Seroukhov }
00007 { }
00008 {*********************************************************}
00009
00010 {@********************************************************}
00011 { Copyright (c) 1999-2006 Zeos Development Group }
00012 { }
00013 { License Agreement: }
00014 { }
00015 { This library is distributed in the hope that it will be }
00016 { useful, but WITHOUT ANY WARRANTY; without even the }
00017 { implied warranty of MERCHANTABILITY or FITNESS FOR }
00018 { A PARTICULAR PURPOSE. See the GNU Lesser General }
00019 { Public License for more details. }
00020 { }
00021 { The source code of the ZEOS Libraries and packages are }
00022 { distributed under the Library GNU General Public }
00023 { License (see the file COPYING / COPYING.ZEOS) }
00024 { with the following modification: }
00025 { As a special exception, the copyright holders of this }
00026 { library give you permission to link this library with }
00027 { independent modules to produce an executable, }
00028 { regardless of the license terms of these independent }
00029 { modules, and to copy and distribute the resulting }
00030 { executable under terms of your choice, provided that }
00031 { you also meet, for each linked independent module, }
00032 { the terms and conditions of the license of that module. }
00033 { An independent module is a module which is not derived }
00034 { from or based on this library. If you modify this }
00035 { library, you may extend this exception to your version }
00036 { of the library, but you are not obligated to do so. }
00037 { If you do not wish to do so, delete this exception }
00038 { statement from your version. }
00039 { }
00040 { }
00041 { The project web site is located on: }
00042 { http:
00043 { http:
00044 { svn:
00045 { }
00046 { http:
00047 { http:
00048 { }
00049 { }
00050 { }
00051 { Zeos Development Group. }
00052 {********************************************************@}
00053
00054 unit ZDbcLogging;
00055
00056 interface
00057
00058 {$I ZDbc.inc}
00059
00060 uses SysUtils, ZClasses;
00061
00062 type
00063
00064 {** Defines a time or the message. }
00065 TZLoggingCategory = (lcConnect, lcDisconnect, lcTransaction, lcExecute, lcOther);
00066
00067 {** Defines a object for logging event. }
00068 TZLoggingEvent = class (TObject)
00069 private
00070 FCategory: TZLoggingCategory;
00071 FProtocol: string;
00072 FMessage: string;
00073 FErrorCode: Integer;
00074 FError: string;
00075 FTimestamp: TDateTime;
00076 public
00077 constructor Create(Category: TZLoggingCategory; Protocol: string;
00078 Msg: string; ErrorCode: Integer; Error: string);
00079
00080 function AsString: string;
00081
00082 property Category: TZLoggingCategory read FCategory;
00083 property Protocol: string read FProtocol;
00084 property Message: string read FMessage;
00085 property ErrorCode: Integer read FErrorCode;
00086 property Error: string read FError;
00087 property Timestamp: TDateTime read FTimestamp;
00088 end;
00089
00090 {** Defines an interface to accept logging events. }
00091 IZLoggingListener = interface (IZInterface)
00092 ['{53559F5F-AC22-4DDC-B2EA-45D21ADDD2D4}']
00093
00094 procedure LogEvent(Event: TZLoggingEvent);
00095 end;
00096
00097 implementation
00098
00099 { TZLoggingEvent }
00100
00101 {**
00102 Constructs this logging event.
00103 @param Protocol a DBC protocol.
00104 @param Msg a description message.
00105 @param ErrorCode an error code.
00106 @param Error an error message.
00107 }
00108 constructor TZLoggingEvent.Create(Category: TZLoggingCategory;
00109 Protocol: string; Msg: string; ErrorCode: Integer; Error: string);
00110 begin
00111 FCategory := Category;
00112 FProtocol := Protocol;
00113 FMessage := Msg;
00114 FErrorCode := ErrorCode;
00115 FError := Error;
00116 FTimestamp := Now;
00117 end;
00118
00119 {**
00120 Gets a string representation for this event.
00121 @returns a string representation.
00122 }
00123 function TZLoggingEvent.AsString: string;
00124 begin
00125 Result := FormatDateTime('yyyy-mm-dd hh:mm:ss', FTimestamp) + ' cat: ';
00126 case FCategory of
00127 lcConnect: Result := Result + 'Connect';
00128 lcDisconnect: Result := Result + 'Disconnect';
00129 lcTransaction: Result := Result + 'Transaction';
00130 lcExecute: Result := Result + 'Execute';
00131 else Result := Result + 'Other';
00132 end;
00133 if Protocol <> '' then
00134 Result := Result + ', proto: ' + FProtocol;
00135 Result := Result + ', msg: ' + FMessage;
00136 if (FErrorCode <> 0) or (FError <> '') then
00137 begin
00138 Result := Result + ', errcode: ' + IntToStr(FErrorCode)
00139 + ', error: ' + FError;
00140 end;
00141 end;
00142
00143 end.
00144