[Tutor] Class understanding

Joe Bennett jammer10000 at gmail.com
Tue Nov 24 17:27:05 CET 2009


Hi all... Have been attempting to understand classes... Been getting
along without them for a while now and feel it's time to jump in....

What I want to do it start a log with the logging module... I have
this working without classes, but want to try... Here is a snippet of
the code that I am hacking on:


class logger():





                        import logging
                        logging.basicConfig(level=logging.INFO,
                                            format='%(asctime)s -
%(name)-12s - %(levelname)-8s - %(message)s',
                                            #format='%(asctime)s
%(levelname)s %(message)s',
                                            filename='T2Notify.log',
                                            filemode='a')
                        logging_output =
logging.getLogger('logging_output.core')
                        print "Log set up"

                        def write2log(log_info):

                                    logging_output.info("log started")
                                    print "written to log"
                                    return()


logger()
logger.write2log(log_info)



What I want to do it be able to set up the log, but have something
outside the class be able to write log updates to write2log under the
logger class... the logger.write2log() is not working :)... Any ideas,
encouragement, or pointers to good docs would be helpful... I've done
a lot of searching via Google on classes, and it's all confusing to
me...




-Joe


More information about the Tutor mailing list