ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/branches/udr/udr/source/FBUDRController.pas
(Generate patch)
# Line 73 | Line 73
73      AllowConfigFileOverrides: boolean;
74      LogFileNameTemplate: AnsiString;
75      ConfigFileNameTemplate: AnsiString;
76 <    ForceWriteJournalEntries: boolean;
76 >    ForceWriteLogEntries: boolean;
77      LogOptions: TFBUDRControllerLogOptions;
78      ThreadSafeLogging: boolean;
79    end;
80  
81 <  {LogFileNameTemplate, ConfigFileName and DebugLogTemplate macros:
81 >  {LogFileNameTemplate and ConfigFileName macros:
82      $LOGDIR = Firebird log directory
83      $UDRDIR = Firebird UDR directory
84      $TEMP = System temp directory
# Line 91 | Line 91
91            AllowConfigFileOverrides: false;
92            LogFileNameTemplate:'$LOGDIR$TIMESTAMP$MODULE.log';
93            ConfigFileNameTemplate: '$UDRDIR$MODULE.conf';
94 <          ForceWriteJournalEntries: false;
94 >          ForceWriteLogEntries: false;
95            LogOptions: [];
96            ThreadSafeLogging: false);
97  
# Line 130 | Line 130
130                                           aName: AnsiString; factory: TObject);
131      procedure FreeFactoryList;
132      procedure LoadConfig;
133 +    function NeedLogStream: boolean;
134    public
135      constructor Create(status: Firebird.IStatus; udrPlugin: Firebird.IUdrPlugin;
136                                           aTheirUnloadFlag: booleanPtr; var aMyUnloadFlag: booleanPtr);
137      destructor Destroy; override;
138      procedure FBSetStatusFromException(E: Exception; aStatus: Firebird.IStatus);
138    function GetLogStream: TStream;
139      function ProcessTemplateMacros(aTemplate: AnsiString): AnsiString;
140      procedure WriteToLog(Msg: AnsiString); overload;
141      procedure WriteToLog(aTitle: AnsiString; Params: IFBUDRInputParams); overload;
# Line 2098 | Line 2098
2098      aConfigFileName: Ansistring;
2099   begin
2100    aConfigFileName := ProcessTemplateMacros(FBUDRControllerOptions.ConfigFileNameTemplate);
2101 <  if (FConfigFile = nil) and FileExists(aConfigFileName) then
2101 >  if (FConfigFile = nil) and (aConfigFileName <> '') and FileExists(aConfigFileName) then
2102    begin
2103      FConfigFile := TIniFile.Create(aConfigFileName);
2104      {$if declared(TStringArray)}
# Line 2111 | Line 2111
2111      begin
2112        LogFileNameTemplate := FConfigFile.ReadString('Controller','LogFileNameTemplate',LogFileNameTemplate);
2113        WriteToLog('LogFileNameTemplate = ' + LogFileNameTemplate);
2114 <      ForceWriteJournalEntries := FConfigFile.ReadBool('Controller','ForceWriteJournalEntries',ForceWriteJournalEntries);
2115 <      WriteToLog('ForceWriteJournalEntries = ' + BooleanToStr(ForceWriteJournalEntries ,'true','false'));
2114 >      ForceWriteLogEntries := FConfigFile.ReadBool('Controller','ForceWriteLogEntries',ForceWriteLogEntries);
2115 >      WriteToLog('ForceWriteLogEntries = ' + BooleanToStr(ForceWriteLogEntries ,'true','false'));
2116        ThreadSafeLogging := FConfigFile.ReadBool('Controller','ThreadSafeLogging',ThreadSafeLogging);
2117        WriteToLog('ThreadSafeLogging = ' + BooleanToStr(ThreadSafeLogging,'true','false'));
2118        if GetLogOptions( FConfigFile.ReadString('Controller','LogOptions',''),aLogOptions) then
# Line 2122 | Line 2122
2122    end;
2123   end;
2124  
2125 + function TFBUDRController.NeedLogStream: boolean;
2126 + var FilePathName: AnsiString;
2127 + begin
2128 +  Result := false;
2129 +  if FLogStream = nil then
2130 +  begin
2131 +    FilePathName := ProcessTemplateMacros(FBUDRControllerOptions.LogFileNameTemplate);
2132 +    if FilePathName = '' then
2133 +      Exit;
2134 +    if FJnlOpenAppend then
2135 +    begin
2136 +      FLogStream := TFileStream.Create(FilePathName,fmOpenWrite or fmShareDenyNone);
2137 +      FLogStream.Seek(0, soFromEnd);
2138 +    end
2139 +    else
2140 +    begin
2141 +      FLogStream := TFileStream.Create(FilePathName,fmCreate or fmShareDenyNone);
2142 +      FJnlOpenAppend := true;
2143 +    end;
2144 +  end;
2145 +  Result := true;
2146 + end;
2147 +
2148   function TFBUDRController.LogOptionsToStr(aLogOptions: TFBUDRControllerLogOptions): AnsiString;
2149   var i: TFBUDRControllerLogOption;
2150      separator: AnsiString;
# Line 2191 | Line 2214
2214    WriteToLog(SExceptionRaised + LineEnding + E.Message);
2215   end;
2216  
2194 function TFBUDRController.GetLogStream: TStream;
2195 var FilePathName: AnsiString;
2196 begin
2197  if FLogStream = nil then
2198  begin
2199    FilePathName := ProcessTemplateMacros(FBUDRControllerOptions.LogFileNameTemplate);
2200    if FJnlOpenAppend then
2201    begin
2202      FLogStream := TFileStream.Create(FilePathName,fmOpenWrite or fmShareDenyNone);
2203      FLogStream.Seek(0, soFromEnd);
2204    end
2205    else
2206      FLogStream := TFileStream.Create(FilePathName,fmCreate or fmShareDenyNone);
2207  end;
2208  Result := FLogStream;
2209  FJnlOpenAppend := true;
2210 end;
2211
2217   procedure TFBUDRController.WriteToLog(Msg: AnsiString);
2218   var LogEntry: AnsiString;
2219   begin
2220 +  if not NeedLogStream then
2221 +    Exit; {no log file available}
2222    LogEntry := Format(sLogFormat,[FBFormatDateTime(GetDateTimeFmt,Now),Msg]) + LineEnding;
2223    if FBUDRControllerOptions.ThreadSafeLogging then
2224    begin
2225      FCriticalSection.Enter;
2226      try
2227 <      GetLogStream.Write(LogEntry[1],Length(LogEntry));
2228 <      if FBUDRControllerOptions.ForceWriteJournalEntries then
2227 >      FLogStream.Write(LogEntry[1],Length(LogEntry));
2228 >      if FBUDRControllerOptions.ForceWriteLogEntries then
2229          FreeAndNil(FLogStream);
2230      finally
2231        FCriticalSection.Leave;
2232      end;
2233    end
2234    else
2235 <    GetLogStream.Write(LogEntry[1],Length(LogEntry));
2235 >    FLogStream.Write(LogEntry[1],Length(LogEntry));
2236   end;
2237  
2238   function TFBUDRController.CharSetIDToText(att: IAttachment; id: integer): AnsiString;
# Line 2252 | Line 2259
2259             'SQLType = ' + GetSQLTypeName + NewLineTAB +
2260             'sub type = ' + IntToStr(getSubType) + NewLineTAB +
2261             'Scale = ' + IntToStr(getScale) + NewLineTAB +
2262 <           'Charset = '  + CharSetIDToText(Params.GetAttachment,getCharSetID) +  NewLineTAB +
2262 >           'Charset = '  + CharSetIDToText((Params as TFBUDRInputParams).GetAttachment,getCharSetID) +  NewLineTAB +
2263             BooleanToStr(getIsNullable,'Nullable','Not Nullable') + NewLineTAB +
2264             'Size = ' + IntToStr(GetSize) + NewLineTAB +
2265             'Value = ' + BooleanToStr(IsNull,'NULL',GetStrValue(Params[i] as TColumnMetaData)) + LineEnding;
# Line 2308 | Line 2315
2315                   'SQLType = ' + GetSQLTypeName + NewLineTAB +
2316                   'sub type = ' + IntToStr(getSubType) + NewLineTAB +
2317                   'Scale = ' + IntToStr(getScale) + NewLineTAB +
2318 <                 'Charset = '  + CharSetIDToText(OutputData.GetAttachment,getCharSetID) +  NewLineTAB +
2318 >                 'Charset = '  + CharSetIDToText((OutputData as TFBUDROutputParams).GetAttachment,getCharSetID) +  NewLineTAB +
2319                   BooleanToStr(getIsNullable,'Nullable','Not Nullable') + NewLineTAB +
2320                   'Size = ' + IntToStr(GetSize) + NewLineTAB +
2321                   'Value = ' + BooleanToStr(IsNull,'NULL', GetStrValue(OutputData[i] as TColumnMetaData)) + LineEnding;
# Line 2325 | Line 2332
2332    if loReadOnlyQueries in FBUDRControllerOptions.LogOptions then
2333      JnlOptions := JnlOptions + [joReadOnlyQueries];
2334    if JnlOptions <> [] then
2335 <    context.GetAttachment.StartJournaling(GetLogStream,JnlOptions);
2335 >  begin
2336 >    if NeedLogStream then
2337 >      context.GetAttachment.StartJournaling(FLogStream,JnlOptions);
2338 >  end;
2339   end;
2340  
2341   function TFBUDRController.HasConfigFile: boolean;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines