Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   handle a log file. (http://www.velocityreviews.com/forums/t336652-handle-a-log-file.html)

Zunbeltz Izaola 10-07-2004 10:47 AM

handle a log file.
 

Hi,

I've a GUI program (wxPython) that comunicates with a machine with UDP
sockets. Every sended socket is writted to file for inspection if
there is problem. What ocurs is that sometimes the file grows to much
(32Mb) and the program has problems to manage it. Is any way to
control the size of the file?

Thanks in advance

Zunbeltz

--
Zunbeltz Izaola Azkona | wmbizazz at lg dot ehu
dotes
Materia Kondentsatuaren Fisika Saila |
Zientzia eta Teknologia Fakultatea | Phone: 34946015326
Euskal Herriko Unibertsitatea |
PK 644 | Fax: 34 944648500
48080 Bilbo (SPAIN) |

Peter L Hansen 10-07-2004 11:04 AM

Re: handle a log file.
 
Zunbeltz Izaola wrote:
> I've a GUI program (wxPython) that comunicates with a machine with UDP
> sockets. Every sended socket is writted to file for inspection if
> there is problem. What ocurs is that sometimes the file grows to much
> (32Mb) and the program has problems to manage it. Is any way to
> control the size of the file?


Use the standard logging module. It provides the capability for
an automatically "rotating" log file which will handle rolling
over and deleting/renaming the previous file automatically.

You may need to write your own formatter, depending on the
nature of your log entries...
-Peter

Josiah Carlson 10-07-2004 03:38 PM

Re: handle a log file.
 

> I've a GUI program (wxPython) that comunicates with a machine with UDP
> sockets. Every sended socket is writted to file for inspection if
> there is problem. What ocurs is that sometimes the file grows to much
> (32Mb) and the program has problems to manage it. Is any way to
> control the size of the file?


if f.tell() > 2**25:
print "my file is to big"
fn = f.name
f.close()
#destroy the logfile
f = open(fn, 'w')

Probably not precisely what you want, but it will "control the size of
the file".

- Josiah


Zunbeltz Izaola 10-08-2004 01:12 PM

Re: handle a log file.
 
Peter L Hansen <peter@engcorp.com> writes:

> Zunbeltz Izaola wrote:
> > I've a GUI program (wxPython) that comunicates with a machine with UDP
> > sockets. Every sended socket is writted to file for inspection if
> > there is problem. What ocurs is that sometimes the file grows to much
> > (32Mb) and the program has problems to manage it. Is any way to
> > control the size of the file?

>
> Use the standard logging module. It provides the capability for
> an automatically "rotating" log file which will handle rolling
> over and deleting/renaming the previous file automatically.
>
> You may need to write your own formatter, depending on the
> nature of your log entries...
> -Peter


Thanks to all for the response. I have use RotatingFileHandler and I
think it works smoothly.
Thaks for the point

Zunbetlz

--
Zunbeltz Izaola Azkona | wmbizazz at lg dot ehu
dotes
Materia Kondentsatuaren Fisika Saila |
Zientzia eta Teknologia Fakultatea | Phone: 34946015326
Euskal Herriko Unibertsitatea |
PK 644 | Fax: 34 944648500
48080 Bilbo (SPAIN) |


All times are GMT. The time now is 09:50 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.