Re: threads and logfile rotation
- From: Thomas Kratz <ThomasKratz@xxxxxxxxxxxxxxxx>
- Date: Tue, 31 Jul 2007 17:24:48 +0200
zentara wrote:
On Mon, 30 Jul 2007 18:56:40 +0200, Thomas Kratz
<ThomasKratz@xxxxxxxxxxxxxxxx> wrote:
I am a bit stumped with handling logfile rotation with a threaded app.
The below test script dies with "rename failed, Permission denied".
I assume this is because of the detached thread still referencing the filehandle because it got copied at thread creation.
Moving the thread creation before creation of the file solves this, but it is not really what I want. Ideally the thread should be able to log as well to the copied handle.
Is there a way around this?
(perl 5.88 under Win23 with threads 1.64)
I don't know how this will work on win32, but the preffered way
of having threads share a filehandle, is by passing in the fileno;
usually through a shared variable, but this passes it in directly.
Yes, that is the easy part :-)
(works under Win32 as well, I am using this for sockets already)
But the problem remains how to get the filehandle closed again to be able to rename it.
Signaling all the threads to close the filehandle and waiting for all of them to signal back 'done' is more than ugly.
I think I'll have to change the logging mechanism. Perhaps it is better to set up a queue for log messages and only the main thread logs them to file. That way my existing logfile rotation can be used without changes.
But I'll have to change object initiation for my Win32 service as well because the logfile gets created very early in the init stage of the base object.....
Back to the drawing board!
Thanks,
Thomas
--
$/=$,,$_=<DATA>,s,(.*),$1,see;__END__
s,^(.*\043),,mg,@_=map{[split'']}split;{#>J~.>_an~>>e~......>r~
$_=$_[$%][$"];y,<~>^,-++-,?{$/=--$|?'"':#..u.t.^.o.P.r.>ha~.e..
'%',s,(.),\$$/$1=1,,$;=$_}:/\w/?{y,_, ,,#..>s^~ht<._..._..c....
print}:y,.,,||last,,,,,,$_=$;;eval,redo}#.....>.e.r^.>l^..>k^.-
.
- References:
- threads and logfile rotation
- From: Thomas Kratz
- Re: threads and logfile rotation
- From: zentara
- threads and logfile rotation
- Prev by Date: Re: Both Methods and Indexing for Objects?
- Next by Date: Re: Variable declaration - C vs script style
- Previous by thread: Re: threads and logfile rotation
- Next by thread: deleting duplicates in array using references
- Index(es):