Efficient way of looging in python

Discussion in 'Python' started by maitreymishra23@gmail.com, Apr 25, 2013.

  1. Guest

    Hi,

    I need an efficient way of logging using python.
    My problem statemnt:
    1. I have multiple processes using the same logging file.
    I need solutions to the following:
    a) If multiple processes are trying to write to the same file, I need to prevent that. Otherwise, the logging messages will be puzzling to the user as he would see logging messages from one module than may be some other following it.

    Please let me know if there is an efficient way to do it.

    Thanks!

    Br,
    Maitrey
    , Apr 25, 2013
    #1
    1. Advertising

  2. > a) If multiple processes are trying to write to the same file, I need to prevent that.

    Two things: Use some sort of file locking. You can get the lockfile
    module from PyPI. Include at least the process id as one of the
    logging fields in your formatter. I haven't don't enough with the
    logging module to know it it supports some sort of "name" field, which
    would make the different messages more easily distinguished, but if
    so, that would be a better alternative to the process id.

    Skip
    Skip Montanaro, Apr 25, 2013
    #2
    1. Advertising

  3. Roozbeh Guest

    You can also add several handlers to your logger with different levels, so that one Filehandler passes the errors to a log file and StreamHandler passes messages with a different level to the output stream.
    Also by setting the basicConfig of the logger you can format the log messages so that you would see where the messages are originating from.
    Roozbeh, Apr 25, 2013
    #3
    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. Brent Minder
    Replies:
    3
    Views:
    389
    Brent
    Dec 28, 2003
  2. Peter
    Replies:
    1
    Views:
    362
    Steve C. Orr [MVP, MCSD]
    Nov 9, 2004
  3. Rahul
    Replies:
    1
    Views:
    443
    Joerg Jooss
    Feb 1, 2007
  4. Maitrey Mishra

    Re: Efficient way of looging in python

    Maitrey Mishra, May 2, 2013, in forum: Python
    Replies:
    0
    Views:
    103
    Maitrey Mishra
    May 2, 2013
  5. Maitrey Mishra

    Re: Efficient way of looging in python

    Maitrey Mishra, May 2, 2013, in forum: Python
    Replies:
    0
    Views:
    111
    Maitrey Mishra
    May 2, 2013
Loading...

Share This Page