Facing issue with Python loggin logger for printing object value

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

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

Share This Page