Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #28061

Re: Can I get logging.FileHandler to close the file on each emit?

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.005
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'failing': 0.05; 'method,': 0.07; 'subject:file': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'that).': 0.09; 'linux)': 0.16; 'needed?': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subclassing': 0.16; 'wording': 0.16; 'wrote:': 0.17; 'url:dev': 0.17; 'windows': 0.19; 'module': 0.19; '(not': 0.20; 'not,': 0.21; '(on': 0.22; "i'd": 0.22; 'tried': 0.25; 'header:In- Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; '[1]': 0.27; 'logging': 0.27; 'correct': 0.28; 'header:X-Complaints-To:1': 0.28; 'implies': 0.29; 'code': 0.31; 'url:python': 0.32; 'file': 0.32; 'from:addr:yahoo.co.uk': 0.32; 'running': 0.32; 'event.': 0.33; 'to:addr:python-list': 0.33; 'that,': 0.34; 'wrong': 0.34; 'process,': 0.35; 'subject:?': 0.35; 'something': 0.35; 'next': 0.35; 'received:org': 0.36; 'but': 0.36; 'url:org': 0.36; 'url:library': 0.36; 'should': 0.36; 'possible': 0.37; 'subject:: ': 0.38; 'mark': 0.38; 'url:docs': 0.38; 'delete': 0.38; 'to:addr:python.org': 0.39; 'little': 0.39; 'where': 0.40; 'header:Received:5': 0.40; 'your': 0.60; 'close': 0.63; 'email addr:gmail.com': 0.63; 'subject:get': 0.81; '(your': 0.84; 'scratch,': 0.84; 'subject:skip:l 10': 0.84; 'windows)': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Mark Lawrence <breamoreboy@yahoo.co.uk>
Subject Re: Can I get logging.FileHandler to close the file on each emit?
Date Wed, 29 Aug 2012 13:49:33 +0100
References <3570ffff-749a-44c4-ab9e-10c37d9526e8@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host host-92-24-214-5.ppp.as43234.net
User-Agent Mozilla/5.0 (Windows NT 6.0; rv:14.0) Gecko/20120713 Thunderbird/14.0
In-Reply-To <3570ffff-749a-44c4-ab9e-10c37d9526e8@googlegroups.com>
X-Antivirus avast! (VPS 120829-0, 29/08/2012), Outbound message
X-Antivirus-Status Clean
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.3931.1346244515.4697.python-list@python.org> (permalink)
Lines 23
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1346244515 news.xs4all.nl 6846 [2001:888:2000:d::a6]:58706
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:28061

Show key headers only | View raw


On 29/08/2012 11:18, rikardhulten@gmail.com wrote:
> I use logging.FileHandler (on windows) and I would like to be able to delete the file while the process is running and have it create the file again on next log event.
>
> On windows (not tried linux) this is not possible because the file is locked by the process, can I get it to close the file after each log event?
>
> If not, would the correct thing to do be to write my own LogHandler with this behavior?
>
> / Rikard
>

I know little about the logging module but given that the FileHandler[1] 
has a close method, can you simply call that, delete the file and reopen 
where needed?  Failing that I'd look at subclassing existing code and 
not writing your own (Your wording implies to me that you're thinking of 
writing something from scratch, my apologies should I be wrong on that).

[1] http://docs.python.org/dev/library/logging.handlers.html

-- 
Cheers.

Mark Lawrence.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Can I get logging.FileHandler to close the file on each emit? rikardhulten@gmail.com - 2012-08-29 03:18 -0700
  Re: Can I get logging.FileHandler to close the file on each emit? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-08-29 13:49 +0100
    Re: Can I get logging.FileHandler to close the file on each emit? rikardhulten@gmail.com - 2012-08-29 05:57 -0700
  Re: Can I get logging.FileHandler to close the file on each emit? Dieter Maurer <dieter@handshake.de> - 2012-08-30 09:24 +0200

csiph-web