Is there any tail like program, that works for lazarus log files on windows?
I found tail apps for win, but none of them can open a lazarus --debug-log while lazarus is open.
Martin

Mailing lists / lazarus / 2010-07
19 messages · 7 people · –
Reply by email Subscribe to this list Your subscription
Read-only archive. Use j and k to move between messages.
Is there any tail like program, that works for lazarus log files on windows?
I found tail apps for win, but none of them can open a lazarus --debug-log while lazarus is open.
Martin
program tail;
{$mode objfpc}{$H+}
uses
Classes, Math;
var
names : TStringList;
lines : TStringList;
linescount : Integer;
l, err : Integer;
i, j : integer;
begin
names:=TStringList.Create;
linescount:=20;
i:=1;
while i<=Paramcount do begin
if lowercase(ParamStr(i))='-n' then begin
Val(ParamStr(i+1), l, err);
if err=0 then linescount:=l;
inc(i);
end else
names.Add(ParamStr(i));
inc(i);
end;
lines:=TStringList.Create;
for i:=0 to names.Count-1 do begin
lines.Clear;
try
lines.LoadFromFile(names[i]);
for j:=Max(0, lines.Count-linescount) to lines.Count-1 do
writeln(lines[j]);
except
end;
end;
lines.Free;
names.Free;
end.actually, i'm wrong here.
It seems that debug-log file created doesn't allow sharing
thanks,
dmitry
To make the file sharable at Windows you need to apply this patch to lcl proc (and eventually rebuild LCL and Lazarus): After that any program can read/write to the logging file
?Index: lclproc.pas
=================================================================== --- lclproc.pas (revision 26528)
+++ lclproc.pas (working copy)
@@ -2051,6 +2051,8 @@
Result := ExpandFileNameUTF8(Result);
end;+var
+ fm: Byte;
begin
DebugText := nil;
DebugFileName := GetDebugFileName;
@@ -2058,11 +2060,19 @@
(DirPathExists(ExtractFileDir(DebugFileName))) then begin
new(DebugText);
try
+ fm:=Filemode;
+ FileMode:=fmShareDenyNone;
Assign(DebugText^, DebugFileName);
if FileExistsUTF8(DebugFileName) then
Append(DebugText^)
- else
+ else begin
Rewrite(DebugText^);
+ // recreating the file to be sharable!
+ Close(DebugText^);
+ Assign(DebugText^, DebugFileName);
+ Append(DebugText^)
+ end;
+ Filemode:=fm;
except
Freemem(DebugText);
DebugText := nil;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: lclproc.patch
Type: application/octet-stream
Size: 909 bytes
Desc: not available
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20100717/988c84fd/attachment.obj>Is there any tail like program, that works for lazarus log files on windows? I found tail…
I found tail apps for win, but none of them can open a lazarus --debug-log while lazarus is open.
This can be due to either
- Lazarus denies any access to the open file
or
- the programs request exclusive access, rejected for already open files.
DoDi
To make the file sharable at Windows you need to apply this patch to lcl proc (and…
To make the file sharable at Windows you need to apply this patch to lcl proc (and eventually rebuild LCL and Lazarus): After that any program can read/write to the logging file
Is it really that complicated under windows to open a file shared readable?
Why is an Assign, Close, Assign, Append needed?
Mattias
Mattias Gaertner wroteIs it really that complicated under windows to open a file shared readable? Why is an Assign, Close, Assign, Append needed?
You're right! There's no reason for such complexity. Changing Filemode flag to fmShareDenyNone (or fmShareDenyWrite) is enough to make the file readable, even if file is created via Rewrite() function.
thanks,
dmitry
To make the file sharable at Windows you need to apply this patch to lcl proc (and…
dmitry boyarintsev wrote+ fm:=Filemode; + FileMode:=fmShareDenyNone;
this is what i was fixing to suggest to check and then i saw your followup...
On Sat, 17 Jul 2010 14:33:03 +0000 Is it really that complicated under windows to open a…
You need to make sure a file exists. IIRC it is not possible to create a file for sharing, you can only open a file sharable
Marc
Marc Weustink wroteYou need to make sure a file exists. IIRC it is not possible to create a file for sharing, you can only open a file sharable
It's possible. at least the following example did work on Windows.
begin
filemode:=fmShareDenyNone;
assign(f, 'c:\test.txt'); rewrite(f);
writeln(f,'test');
writeln('press enter to unlock file');
readln;
close(f);
end.The newly created c:\test.txt was sharable.
AFAIK, it's "impossible" for TFileStream using fmCreate flag. fmCreate flag causes a file to be re-created without sharing (at Windows).
thanks,
dmitry
You need to make sure a file exists. IIRC it is not possible to create a file for…
You mean that the Append is that stupid, that it needs an already existing file? Or is that behaviour required for compatibility reasons?
At least on Windows all files are created or opened with the unique CreateFile procedure - do other platforms require multiple different calls for that purpose?
DoDi
It's possible. at least the following example did work on Windows. begin…
Did you try to stop at this point, or even before WriteLn, and check whether the file is accessible from other applications?
I can not remember any file attribute "shareable" on Windows. At least FAT filesystems have no such file attribute.
It might be another issue, though, that new files become *visible* to other processes only after they have been closed at least once. Same considerations apply to the file size, that is updated (on disk) only when a file is closed. I dunno whether it's possible to read added content, before the file has been closed. That would mean that *all* log files have to be closed and reopened frequently (after every write), to give other processes a chance to also read the added text. Kind of a Flush or Sync procedure would be nice to have, for that purpose...
DoDi
It's possible. at least the following example did work on Windows. begin…
Yes, i've to admit that I don't use assign etc. but since it is the case for filestreams ans plain winapi, I assumed it would be the case for assign too.
Marc
Did you try to stop at this point, or even before WriteLn, and check whether the file is…
Hello Lazarus-List,
you wrote> AFAIK, it's "impossible" for TFileStream using fmCreate flag. fmCreate > flag causes a file to be re-created without sharing (at Windows).
HPD> I can not remember any file attribute "shareable" on Windows. At least HPD> FAT filesystems have no such file attribute.
fmCreate is = -1 so no other flags can be added to the TFileStream creation.
HPD> It might be another issue, though, that new files become *visible* to HPD> other processes only after they have been closed at least once. Same
In Windows at least, a file is visible as soon as it has been created. Assign does not create the file.
HPD> considerations apply to the file size, that is updated (on disk) only HPD> when a file is closed. I dunno whether it's possible to read added HPD> content, before the file has been closed.
When reading a file which is being opened by another process too you get realtime length information about the file size, but directory enumeration functions only check the information on disk. So to get real time information about file sizes you must open each file and check its size.
HPD> That would mean that *all* log
HPD> files have to be closed and reopened frequently (after every write), to HPD> give other processes a chance to also read the added text. Kind of a HPD> Flush or Sync procedure would be nice to have, for that purpose...
No need as the file handle is shared between both (or n) processes, but each one have its own file pointers. File size is shared between both processes.
I'm talking about windows with NT kernel. Win98 and others I'm not sure.
Did you try to stop at this point, or even before WriteLn, and check whether the file is…
Hans-Peter Diettrich wroteDid you try to stop at this point, or even before WriteLn, and check whether the file is accessible from other applications?
Yes. I did.
Hans-Peter Diettrich wroteYou mean that the Append is that stupid, that it needs an already existing file? Or is that behaviour required for compatibility reasons?
It's compatibility with Turbo Pascal file operations.
thanks,
dmitry
HPD> I can not remember any file attribute "shareable" on Windows. At least HPD> FAT…
Jos? Mejuto schrieb:
Thanks for the clarification :-)
I'm talking about windows with NT kernel. Win98 and others I'm not sure.
Most probably my version described older (DOS/Win3...) behaviour.
DoDi
It's possible. at least the following example did work on Windows. begin…
Can you create a new patch?
Mattias
Mattias Gaertner wroteCan you create a new patch?
Here you go. Has just tested it on Vista64.
Index: lclproc.pas
=================================================================== --- lclproc.pas (revision 26738)
+++ lclproc.pas (working copy)
@@ -2051,13 +2051,18 @@
Result := ExpandFileNameUTF8(Result);
end;+var
+ fm : Byte;
+
begin
DebugText := nil;
DebugFileName := GetDebugFileName;
if (length(DebugFileName)>0) and
(DirPathExists(ExtractFileDir(DebugFileName))) then begin
+ fm:=Filemode;
new(DebugText);
try
+ Filemode:=fmShareDenyNone;
Assign(DebugText^, DebugFileName);
if FileExistsUTF8(DebugFileName) then
Append(DebugText^)
@@ -2069,6 +2074,7 @@
// Add extra line ending: a dialog will be shown in windows gui
application
writeln(StdOut, 'Cannot open file: ', DebugFileName+LineEnding);
end;
+ Filemode:=fm;
end;
if DebugText=nil then
begin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: lclproc.patch
Type: application/octet-stream
Size: 867 bytes
Desc: not available
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20100719/56dae45a/attachment.obj>Thanks. Applied in 26809.
Mattias