python can't logging messages to cmd
My code as below, th开发者_如何学Ce problem is log.info("message") can't be printed to my console and log.error("message") can:
log = None
def initLogger():
global log
log = logging.getLogger("JsSDKBuilder")
console = logging.StreamHandler(sys.stdout)
console.setFormatter(logging.Formatter('[%(levelname)s] %(message)s'))
log.setLevel(logging.INFO)
log.addHandler(console)
def main():
"""Preprocessing"""
initLogger()
log.info("info message") //!!!!!!!!!!CANT PRINT OUT PLEASE HELP!!!!!!!
log.error("error message") //works as expected
if __name__ == "__main__":
main(sys.argv[1:])
sorry wired,i run the code in my virtual machine again,it works as expected.
Instead of your own code, use this:
logging.basicConfig(level=logging.INFO)
Do you need to global log
at the top of your main()
?
精彩评论