import logging def log(path): """ Log to multiple locations if multipleLocs is True """ fmt_str = '%(asctime)s - %(levelname)s - %(message)s' formatter = logging.Formatter(fmt_str) logging.basicConfig(filename=path, level=logging.INFO, format=fmt_str) console = logging.StreamHandler() console.setLevel(logging.INFO) console.setFormatter(formatter) logging.getLogger("").addHandler(console) logging.info("This is an informational message") logging.exception("You can't do that!") logging.critical("THIS IS A SHOW STOPPER!!!") logging.error("Ciao!!!") if __name__ == "__main__": #log("sample.log") # log only to file log("sample2.log") # log to file AND console!
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question