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

Discussion in 'Python' started by Dave Angel, Dec 28, 2012.

  1. Dave Angel

    Dave Angel Guest

    On 12/28/2012 09:27 AM, Morten Engvoldsen wrote:
    > Hi Team,
    > i am new to python and i am using python loggin for log the value of the
    > object. Below is my code :
    >
    > class field:
    > field_name = ""
    > length = 0
    > type = 0
    > value = ""
    >
    > def __init__(self, field_name, length, type, value):
    > self.field_name = field_name
    > self.length = length
    > self.type = type
    > self.value = value
    >
    > def toString(self):
    > if self.type == 2:
    > return self.value.zfill(self.length)
    > else:
    > return self.value.ljust(self.length).upper()
    > class record:
    > fields = []
    >
    > def setValue(self, field_name, value):
    > for element in self.fields:
    > if field_name == element.field_name:
    > element.value = value
    >
    > def toString(self):
    > _tempStr = ""
    > for element in self.fields:
    > _tempStr = _tempStr + element.toString()
    > if len(_tempStr) < 80:
    > return _tempStr
    > else:
    > _lines = len(_tempStr) / 80
    > _i = 0
    > _tempStr2 = ""
    > _newline = ""
    > while _i < _lines:
    > _tempStr2 = _tempStr2 + _newline + _tempStr[_i*80:(_i+1)*80]
    > _newline = "\n"
    > _i = _i + 1
    >
    > return _tempStr2
    > class First_betfor00(record):
    >
    > def __init__(self):
    > self.fields = [field("APPLICATION-HEADER", 40, 1, ""),
    > field("TRANSACTION-CODE", 8, 0, "BETFOR00"),
    > field("ENTERPRISE-NUMBER", 11, 2, ""),
    > field("DIVISION", 11, 1, ""),
    > field("SEQUENCE-CONTROL", 4, 2, ""),
    > field("RESERVED-1", 6, 1, ""),
    > field("PRODUCTION-DATE", 4, 1, "MMDD"),
    > field("PASSWORD", 10, 1, ""),
    > field("VERSION", 10, 1, "VERSJON002"),
    > field("NEW-PASSWORD", 10, 1, ""),
    > field("OPERATOR-NO", 11, 1, ""),
    > field("SIGILL-SEAL-USE", 1, 1, ""),
    > field("SIGILL-SEAL-DATE", 6, 1, ""),
    > field("SIGILL-SEAL-KEY", 20, 1, ""),
    > field("SIGILL-SEAL-HOW", 1, 1, ""),
    > field("RESERVED-2", 143, 1, ""),
    > field("OWN-REFERENCE-BATCH", 15, 1, ""),
    > field("RESERVED-3", 9, 1, ""),
    > ]
    > class account(osv.osv_memory):
    > _name = 'account'
    >
    > def create(self,cr,uid,ids,context):
    > logger = logging.getLogger('account')
    > hdlr = logging.FileHandler('/var/tmp/account')
    > formatter = logging.Formatter('%(asctime)s, %(levelname)s,
    > %(message)s')
    > hdlr.setFormatter(formatter)
    > logger.addHandler(hdlr)
    >
    > batch = ""
    > recordCounter = 1
    > dateMMDD = time.strftime('%m%d')
    >
    > betfor00 = Format_betfor00()
    > betfor00.setValue("APPLICATION-HEADER",
    > applicationHeader.toString())
    > betfor00.setValue("ENTERPRISE-NUMBER", enterpriseNumber)
    > betfor00.setValue("PRODUCTION-DATE", dateMMDD)
    > batch = betfor00.toString()
    >
    > line_counter = line_counter + 1
    > log.debug('%(batch)s')
    > return {'type': 'state', 'state':'end'}
    > account()
    >
    >
    > In the above code i am trying to capture the value of 'batch' in the log
    > file, but when i check log file it doesn't have any value printed. my
    > question is is it correct way to capture the object value that is
    > log.debug('%(batch)s')
    >
    > I will really appreciate the answer. Thanks in advance..
    >
    > Regards,
    > Morten
    >
    >

    Then Morten wrote (starting a redundant thread with different subject line):

    Hi Dave,
    Thanks for looking into my issue. You cannot run the program since it is
    in Openerp where python is used as programming language. Here python 2.7 is
    used. Sorry i didn't mention all the detail.

    My program is able to write log for other message in the log file. here
    'batch' is an object and when i try to log the value of 'batch' with
    logger.debug('The value is %s' %batch) , it doesn't log the value. I am not
    sure if it is the correct if it correct formatting syntax for displaying
    Object value.

    Thanks in advance again.. I am new to Python but not in programming
    language..

    .....................................

    Does this "openerp' environment ignore syntax errors? Can you see when things go wrong, or are you stuck with only looking at the zero-length log file ?

    After "fixing" perhaps a half-dozen errors in that one create() method, and fixing lots of other stuff so I could run it at all, I came across the particular clue you're probably missing.

    logger.setLevel(logging.DEBUG)


    Without that, the logger doesn't know which messages should be logged.





    --

    DaveA
    Dave Angel, Dec 28, 2012
    #1
    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. Morten Engvoldsen
    Replies:
    0
    Views:
    114
    Morten Engvoldsen
    Dec 28, 2012
  2. Dave Angel
    Replies:
    0
    Views:
    129
    Dave Angel
    Dec 28, 2012
  3. Morten Engvoldsen
    Replies:
    0
    Views:
    118
    Morten Engvoldsen
    Dec 29, 2012
  4. Chris Angelico
    Replies:
    0
    Views:
    125
    Chris Angelico
    Dec 29, 2012
  5. Dave Angel
    Replies:
    0
    Views:
    98
    Dave Angel
    Dec 29, 2012
Loading...

Share This Page