1

My code as below, the 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.

0

2 Answers 2

1

Instead of your own code, use this:

logging.basicConfig(level=logging.INFO)
Sign up to request clarification or add additional context in comments.

Comments

0

Do you need to global log at the top of your main() ?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.