handle a log file.

Discussion in 'Python' started by Zunbeltz Izaola, Oct 7, 2004.

  1. 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) |
    Zunbeltz Izaola, Oct 7, 2004
    #1
    1. Advertising

  2. 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
    Peter L Hansen, Oct 7, 2004
    #2
    1. Advertising


  3. > 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
    Josiah Carlson, Oct 7, 2004
    #3
  4. Peter L Hansen <> 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) |
    Zunbeltz Izaola, Oct 8, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dietrich
    Replies:
    1
    Views:
    625
    Joe Smith
    Jul 22, 2004
  2. Henrik_the_boss
    Replies:
    0
    Views:
    2,627
    Henrik_the_boss
    Nov 5, 2003
  3. Amratash
    Replies:
    0
    Views:
    497
    Amratash
    Apr 13, 2004
  4. =?Utf-8?B?VG9tIFdpbmdlcnQ=?=

    My.Log.Writeexception not writing to Application Event Log.

    =?Utf-8?B?VG9tIFdpbmdlcnQ=?=, Jan 20, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    2,352
    =?Utf-8?B?VG9tIFdpbmdlcnQ=?=
    Jan 20, 2006
  5. unomystEz
    Replies:
    0
    Views:
    529
    unomystEz
    Nov 19, 2006
Loading...

Share This Page