Re: Facing issue with Python loggin logger for printing object value

Discussion in 'Python' started by Morten Engvoldsen, Dec 29, 2012.

  1. Hi Dave,
    It is able to log the message with:
    logger.debug("value of payment_line is " +repr(payment_line))

    The output is:
    value of payment_line is []

    So it means payment_line is an empty list, so may be it could be reason
    it's not able to enter into the loop since the message in the for loop is
    not logged in the log file.

    Thanks and good night.. :)


    On Sat, Dec 29, 2012 at 7:38 PM, Morten Engvoldsen <>wrote:

    > Hi Dev,
    > Thanks a lot Dev for your reply. It is really a great help. Yes i have
    > fixed what was wrong in the create method like log.debug. I have declared
    > line_counter=1 before the for loop. i will try now to chcek the value of
    > payment_line.
    >
    > Thanks again a lot. I am greateful be a member of this forum :)
    >
    > On Sat, Dec 29, 2012 at 6:10 PM, Dave Angel <> wrote:
    >
    >> On 12/29/2012 11:54 AM, Morten Engvoldsen wrote:
    >> > Hi Dave,
    >> > Thanks a lot for your reply. I have used logging.setLevel(logger.DEBUG)
    >> > because of threshold as you said.
    >> >
    >> > I didn't copy paste the entire program since it was very huge. The

    >> "batch "
    >> > which value i am trying to retrieve is in a a for loop :
    >> >
    >> > for payment in payment_line:
    >> >
    >> > but here payment_line has null value since it was not able to retrieve
    >> > payment line value from the payment object.

    >>
    >> The closest thing Python has to "null value" is called None. If
    >> payment_line is None, then you'll get an exception on that loop.
    >>
    >> As I said a while ago, I have no idea how openerp handles exceptions.
    >> Maybe it's just doing a bare except, and ignoring anything that goes
    >> wrong in your functions. (Very bad practice)
    >>
    >> It could be that payment_line is an empty list. In that case, the loop
    >> will execute zero times. That would also explain the lack of output.
    >>
    >> So if openerp gives you no debugging aid, then you may have to fake it
    >> with the logger. How about logging a simple message just before the loop?
    >>
    >> logger.debug("value of payment_line is " + repr(payment_line))
    >>
    >> Did you ever fix the other things wrong with that create method? Like
    >> using log.debug when the object was called logger? Or incrementing
    >> line_counter when there was no such variable, and when it would vanish
    >> when you exited the method anyway?
    >>
    >>
    >>
    >> --
    >>
    >> DaveA
    >>

    >
    >
     
    Morten Engvoldsen, Dec 29, 2012
    #1
    1. Advertisements

  2. Morten Engvoldsen

    Roy Smith Guest

    In article <>,
    Morten Engvoldsen <> wrote:

    > It is able to log the message with:
    > logger.debug("value of payment_line is " +repr(payment_line))


    As a side note, a better way to write that is

    logger.debug("value of payment_line is %r", payment_line)

    The difference is that the first way, repr(payment_line) is evaluated,
    and the string addition is done, before debug() is called. Only then
    will it be decided if message should be logged, and if not, it will be
    discarded.

    The second way, payment_line will just get passed to debug(). If the
    message is never logged, repr() will never get called. Much more
    efficient that way, especially for debug calls which most of the time
    will not get logged.
     
    Roy Smith, Dec 29, 2012
    #2
    1. Advertisements

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. Morten Engvoldsen
    Replies:
    0
    Views:
    172
    Morten Engvoldsen
    Dec 28, 2012
  2. Dave Angel
    Replies:
    0
    Views:
    181
    Dave Angel
    Dec 28, 2012
  3. Dave Angel
    Replies:
    0
    Views:
    170
    Dave Angel
    Dec 28, 2012
  4. Morten Engvoldsen
    Replies:
    0
    Views:
    173
    Morten Engvoldsen
    Dec 29, 2012
  5. Chris Angelico
    Replies:
    0
    Views:
    175
    Chris Angelico
    Dec 29, 2012
Loading...

Share This Page