[patch_done] TZSQLMonitor logs using WideChar on D2009?
Posted: 24.06.2009, 01:57
My SQL debug log lines
L o o k s l i k e t h i s . a n d a r e v e r y h a r d t o r e a d!
There are also no valid CRLF end-of-lines in the text file, so all log lines are in one big hairy gob of nasty looking text.
I think the TZSQLMonitor.SaveToFile method needs to be "AnsiFied" for D2009 compilation, and viewing the resulting logs in Notepad or other simple text editors.
I played with the source and this seems to fix it:
{**
Saves the logging events to the specified file.
@param FileName a name of the file to write the events.
}
procedure TZSQLMonitor.SaveToFile(const FileName: string);
var
I: Integer;
Stream: TFileStream;
Temp: Ansistring;
Buffer: PAnsiChar;
begin
if not FileExists(FileName) then
Stream := TFileStream.Create(FileName, fmCreate)
else
Stream := TFileStream.Create(FileName, fmOpenWrite or fmShareDenyWrite);
try
for I := 0 to FTraceList.Count - 1 do
begin
Temp := TZLoggingEvent(FTraceList).AsString + #13#10;
Buffer := PAnsiChar(Temp);
Stream.Write(Buffer^, StrLen(Buffer) * sizeof(Ansichar));
end;
finally
Stream.Free;
end;
end;
{**
Handles a new incoming logging event.
@param Event an incoming logging event.
}
procedure TZSQLMonitor.LogEvent(Event: TZLoggingEvent);
var
LogTrace: Boolean;
Stream: TFileStream;
Temp: Ansistring;
Buffer: PAnsiChar;
begin
LogTrace := True;
DoTrace(Event, LogTrace);
if not LogTrace then Exit;
{ Store the event. }
if FMaxTraceCount <> 0 then
begin
if FMaxTraceCount > 0 then
TruncateTraceList(FMaxTraceCount - 1);
FTraceList.Add(TZLoggingEvent.Create(Event.Category, Event.Protocol,
Event.Message, Event.ErrorCode, Event.Error));
end;
{ Save the event. }
if FAutoSave and (FFileName <> '') then
begin
if not FileExists(FFileName) then
Stream := TFileStream.Create(FFileName, fmCreate)
else
Stream := TFileStream.Create(FFileName, fmOpenReadWrite or fmShareDenyWrite);
try
Stream.Seek(0, soFromEnd);
Temp := Event.AsString + #13#10;
Buffer := PAnsiChar(Temp);
Stream.Write(Buffer^, StrLen(Buffer)*sizeof(Ansichar));
finally
Stream.Free;
end;
end;
DoLogTrace(Event);
end;
Thanks!
Kevin G. McCoy
L o o k s l i k e t h i s . a n d a r e v e r y h a r d t o r e a d!
There are also no valid CRLF end-of-lines in the text file, so all log lines are in one big hairy gob of nasty looking text.
I think the TZSQLMonitor.SaveToFile method needs to be "AnsiFied" for D2009 compilation, and viewing the resulting logs in Notepad or other simple text editors.
I played with the source and this seems to fix it:
{**
Saves the logging events to the specified file.
@param FileName a name of the file to write the events.
}
procedure TZSQLMonitor.SaveToFile(const FileName: string);
var
I: Integer;
Stream: TFileStream;
Temp: Ansistring;
Buffer: PAnsiChar;
begin
if not FileExists(FileName) then
Stream := TFileStream.Create(FileName, fmCreate)
else
Stream := TFileStream.Create(FileName, fmOpenWrite or fmShareDenyWrite);
try
for I := 0 to FTraceList.Count - 1 do
begin
Temp := TZLoggingEvent(FTraceList).AsString + #13#10;
Buffer := PAnsiChar(Temp);
Stream.Write(Buffer^, StrLen(Buffer) * sizeof(Ansichar));
end;
finally
Stream.Free;
end;
end;
{**
Handles a new incoming logging event.
@param Event an incoming logging event.
}
procedure TZSQLMonitor.LogEvent(Event: TZLoggingEvent);
var
LogTrace: Boolean;
Stream: TFileStream;
Temp: Ansistring;
Buffer: PAnsiChar;
begin
LogTrace := True;
DoTrace(Event, LogTrace);
if not LogTrace then Exit;
{ Store the event. }
if FMaxTraceCount <> 0 then
begin
if FMaxTraceCount > 0 then
TruncateTraceList(FMaxTraceCount - 1);
FTraceList.Add(TZLoggingEvent.Create(Event.Category, Event.Protocol,
Event.Message, Event.ErrorCode, Event.Error));
end;
{ Save the event. }
if FAutoSave and (FFileName <> '') then
begin
if not FileExists(FFileName) then
Stream := TFileStream.Create(FFileName, fmCreate)
else
Stream := TFileStream.Create(FFileName, fmOpenReadWrite or fmShareDenyWrite);
try
Stream.Seek(0, soFromEnd);
Temp := Event.AsString + #13#10;
Buffer := PAnsiChar(Temp);
Stream.Write(Buffer^, StrLen(Buffer)*sizeof(Ansichar));
finally
Stream.Free;
end;
end;
DoLogTrace(Event);
end;
Thanks!
Kevin G. McCoy