faqts : Computers : Programming : Languages : Python : Snippets

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

9 of 9 people (100%) answered Yes
Recently 7 of 7 people (100%) answered Yes

Entry

Source line number for log purpose

Jul 5th, 2000 10:00
Nathan Wallace, Hans Nowak, Snippet 159, Siggy Bentrup


"""
Packages: miscellaneous.introspection
"""
#! /usr/bin/env python
import sys, traceback
def logger(message):
    file, line, func, txt = traceback.extract_stack(None, 2)[0]
    print '%(file)s:%(line)s: in function %(func)s - %(message)s' \
          % locals()
def main():
    logger( 'Hi there!' )
    logger( 'and again' )
if __name__ == '__main__':
    main()
    logger('Bye')