Return to Snippet

Revision: 31522
at September 8, 2010 19:31 by silviud


Initial Code
def setupLogger(self, log_dir):
                if not isdir(log_dir):
                        os.mkdir(log_dir)

                # create logger
                log_file = join(log_dir, time.strftime('%Y_%m_%d') + '.log')
                logger = logging.getLogger(log_file)
                logger.setLevel(logging.INFO)

                # create console handler and set level to debug
                ch = logging.FileHandler(log_file)
                ch.setLevel(logging.INFO)

                # create formatter
                formatter = logging.Formatter("%(asctime)s - %(levelname)s - %(message)s")

                # add formatter to ch
                ch.setFormatter(formatter)

                # add ch to logger
                logger.addHandler(ch)

                return logger

Initial URL

                                

Initial Description

                                

Initial Title
Python log setup

Initial Tags
python

Initial Language
Python