Liondancer
Liondancer

Reputation: 16469

Writing into log file

I'm not sure why nothing is being written in my log file. The log file is being generated correctly but as soon as I try to do a log.info nothing is written in the log file.

import logging
import os
import sys
import argparse
import datetime

def main(argv):
    global me; me = os.path.basename(argv[0])
    log = logging.getLogger(me) 
    logfile = "testyy.log"
    parser = argparse.ArgumentParser(description=main.__doc__)
    args = parser.parse_args(args=argv[1:])
    if os.path.exists(logfile):
        os.remove(logfile)
    log.addHandler(logging.FileHandler(logfile))
    console = logging.StreamHandler(sys.stderr); console.setLevel(logging.WARNING); log.addHandler(console)
    log.info("{0}: START: {1}".format(me, datetime.datetime.now().ctime()))

if __name__ == "__main__":
    sys.exit(main(sys.argv))

Upvotes: 0

Views: 72

Answers (1)

pestrella
pestrella

Reputation: 9936

Make sure you have the desired log level set. In the case of info logging you must set the following level:

log.setLevel(logging.INFO)

Upvotes: 1

Related Questions